This is a struts2 question.
Currently, I am using i18n for internationalization in my webapp.
Some of my jsp pages has querystring to store the request information.
For example,
http://myWebsite.com/myWebsite/myPage?productId=12345
When users try to switch language, I rewrite the URL by javascript to
http://myWebsite.com/myWebsite/myPage?request_locale=zh_CN
And it loses the query string.
And my urls are used in different ways:
http://myWebsite.com/myWebsite/myPage
http://myWebsite.com/myWebsite/myPage?productId=12345#myAnchor
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3#myAnchor
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3&request_locale=zh_CN
http://myWebsite.com/myWebsite/myPage?productId=12345&key2=value2&key3=value3
...
When I try to handle all this differences in javascript, it becomes so complicated.
Is there any good way to retain the querystrings and anchors after switching locale?
When you rewrite the URL using JS, you should do it based on the current URL.
So, if in the browser is showed
http://myWebsite.com/myWebsite/myPage?productId=12345
you should rewrite it as
http://myWebsite.com/myWebsite/myPage?productId=12345&request_locale=zh_CN
For that, using JS you should get the current URL displayed. Take a look to this question for how to.
Related
I am trying to create a JSON response but I need some things that is easily done in ISML. First I would like to know how I can build a proper URL this should link to a pipeline call with some parameters. The other thing I would like to know is how can I access language property files in a pipelet/java like the istext tag that you can call with ISML
Thank you
If you do not like to use the URL with the pipeline name, you can create a short URL in the back office, or create a URL rewrite rule.
Every parameter you add to the URL will of course be available in the pipeline dictionary.
To get a localized text in Java take a look at the GetLocalizedTextByKey pipelet.
It uses the LocalizationProvider to provide a localized text for a specific key and a locale.
You can also take a look at this Intershop Knowledge Base article if you have access: https://support.intershop.com/kb/index.php/Display/2258M5
If I have a HTML String object, using Selenium in Java, how can I get the browser to open that String as a HTML page? I have seen this done before but I don't remember the format that the URL needs to be.
For this example, let's say the string is :
<h2>This is a <i>test</i></h2>
I looked through this page and couldn't find the answer but I might be overlooking it. For example I tried this URL and it didn't work for me:
data:<h2>This is a <i>test</i></h2>
Here is a link for documentation http://en.wikipedia.org/wiki/Data_URI_scheme. You need to specify MIME-type of data. Try data:text/html,<h2>This is a <i>test</i></h2>
I'd like to change the URL of some pages in my website in the same way as foursquare is doing:
from www.foursquare.com/v/anystring/venueid
to www.foursquare.com/v/venue-name/venueid
For example central park in new york:
https://foursquare.com/v/writeherewhatyouwant/412d2800f964a520df0c1fe3
becomes
https://foursquare.com/v/central-park/412d2800f964a520df0c1fe3
I'm developing a pure JSP/Servlet app, no frameworks, in a Tomcat container.
I'm thought of using tuckey's urlrewritefilter, but I don't see how can I use dynamic values coming from the servlet itself there (the venue name)
How can I accomplish this?
Off the top of my head, here's something you could try:
1) Create a servlet with a servlet-mapping matching the common (prefix) part of the URL (e.g. for foursquare the pattern would be /v/*).
2) In your servlet, retrieve the remaining part of the URL path using request.getPathInfo(). You can then parse it using regular string utilities and convert it to the new path you'd like.
3) Assuming your updated path is in a variable called newUrl, call response.sendRedirect(newUrl) to tell the browser to update its URL. This will also call your servlet again with the new path, so it needs to handle both cases.
See the javadoc for HttpServletResponse.sendRedirect() for more info about how it handles relative vs absolute paths, etc.
I have stream of shortened URLs as received from twitter feeds. I don't need entire page of that URL, but basic meta information like expanded original URL, page title, timestamps etc. I can get the entire page containing these meta as well using curl,wget, but any quicker way to only get the meta? Also, is there any java classes/methods to do this like curl.
HTTP Head requests may be what you are looking for, here is an example that uses curl (in its Python implementation though): Python: Convert those TinyURL (bit.ly, tinyurl, ow.ly) to full URLS
I'm building a webapp using spring MVC and am curious as to whether there is any clean way to make SEO urls.
For example, instead of http://mysite.com/articles/articleId and the such, have:
http://mysite.com/articles/my-article-subject
If you're using the new Spring-MVC annotations, you can use the #RequestMapping and #PathVariable annotations:
#RequestMapping("/articles/{subject}")
public ModelAndView findArticleBySubject(#PathVariable("subject") String subject)
{
// strip out the '-' character from the subject
// then the usual logic returning a ModelAndView or similar
}
I think it is still necessary to strip out the - character.
This might be of interest to you:
http://tuckey.org/urlrewrite/
If you are familiar with mod_rewrite on Apache servers, this is a similar concept.
http://mysite.com/articles/my-article-subject is a much stronger URL than http://mysite.com/articles/articleId - especially if the title and header tags match "my-article-subject" too and you have "my", "article" and "subject" in the content of the page.
For example if you want the url
http:///blog/11/12/2009/my-hello-world-post/
then configure the servlet mapping
<servlet>
<servlet-class>com.blog.Blog</servlet-class>
<servlet-name>blog</servlet-name>
<servlet-class>com.blog.Blog</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>blog</servlet-name>
<url-pattern>/blog/*</url-pattern>
</servlet-mapping>
and in the servlet code
String url = request.getPathInfo();
StringTokenizer tokens = new StringTokenizer(url,"/");
while(tokens.hasMoreTokens()){
out.println(""+tokens.nextToken());
}
Use these params to get the data from database and display to user
The standard Java web frameworks are not ready for those kind of URL.
AFAIK, SpringMVC does not support this kind of URL.
There are two frameworks I'm sure that support this kind of URL: Mentawai and VRaptor.
If you're only looking for a SEO optimization you could design your URLs this way:
http://mysite.com/articles/my-article-subject/articleId
or
http://mysite.com/articles/articleId/my-article-subject
and just ignore the part my-article-subject when evaluating the urls.
Amazon does something like that with their URLs:
http://www.amazon.com/Dark-Crystal-Jean-Pierre-Amiel/dp/B00000JPH6/ref=sr_1_1?ie=UTF8&s=dvd&qid=1240561659&sr=8-1
Here the Text "Dark-Crystal-Jean-Pierre-Amiel" is totally irrelevant because the article is identified by the id B00000JPH6.
Edit: In fact I just noticed that right here on SO this exact technique is used to generate SEO-friendly URLs...
I have used pretty faces http://ocpsoft.org/prettyfaces/ for our application because it was JSF based. This is a very neat solution.
Not sure if it will work for Spring MVC
Have a look at our URL
http://www.skill-guru.com/cat/certification-mock-test
http://www.skill-guru.com/test/81/core-spring-3.0-certification-mock
http://www.skill-guru.com/tutor/Pro+ESL
Earlier we had non SEO friendly URL's with jsession Id's appended to it. Now it is all neat and clean with the help of pretty filter.
This is in very in line with wordpress url.
generate url containing both id and description like this url http://stackoverflow.com/questions/784891/java-and-seo-urls . in the servlet parse the url and then use id for fetching data from database. Same Technique is applies on this stackoverflow page too. look at the url. its http://stackoverflow.com/questions/784891/java-and-seo-urls
however only questionId is considered and description is ignored. try http://stackoverflow.com/questions/784891 or http://stackoverflow.com/questions/784891/abcdxyz . you will get same page. this is very good technique to generate seo urls