I have the following issue:
I'm using Spring-MVC with JSPs.
On my page I want to put a couple of links(with urls) in the content area. I'm getting the names of the links plus the description from a properties file via spring:messages.
Now the question is, what is the best-practice or most elegant way to put the link-urls on the page. Should I hardcode them in the jsp? Should they come from the properties file where I have stored the text which goes on the page, should they come from the controller (where they would be stored in static variables) or should they be passed through all the way using a service and a bean etc.?
I would appreciate your opinion!
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
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.
I have some images stored in /images the problem is that i wish to return a url like so from a class.
/images/test.png
The problem is that in my development machine my url is in the form of
http://localhost/myApp
and in production its in the form of
http://www.mysite.com
so i can't just return /images as this doesn't work on the development machine
I suppose what i am trying to do in Java is the same as teh JSTL tag does
<c:url
So when i am in my development machine it would return
/myApp/images/test.png
and in production
/images/test.png
can anyone help?
Thanks in advance
${request.contextPath}/images/foo
You're probably looking for the context path.
You need to use getContextPath() method on the ServletRequest - and then append the rest of your path:
String url = request.getContextPath() + "/images/test.png";
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