Servlets and Search Engine-Friendly URLs

M

msenin

S

SMC

Hi.

I've website built with JSPs, and it's 99% dynamic content. So I have a
lot of URLs with parameters, e.g.
http://myserver.com/servlet/myServlet?parm1=value1&parm2=value2

etc., but search engines/spiders, such as Google would not index such
links.

So I am trying to somehow mask/transform those URLs so that they appear
to spiders as static pages, e.g.

http://myserver.com/go/servlet/myServlet/parm1-value1.parm2-value2.html

Thanks!

p.s.
I am using TomCat as a standalone web server.

You need a controller servlet (which could be a JSP) that parses those
"friendlier" URLs for the values required by your servlet.

There's no real reason to require parameters to be passed in the
querystring format, it's just convenient because you can use
request.getParameter("parameter_name") to get required values. The
alternative is to create a meaningful URL format that you can parse.

So using your URL example:

/servlet/myServlet/parm1-value1.parm2-value2.html

It can be parsed thusly:

String uri = request.getRequestURI();
uri = uri.substring(0,uri.indexOf(".html"));
String params[] = uri.split(".");
for (int i=0; i<params.length;i++){
String pair[] = params.split("-");
// Do something ...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top