1

I have a site that produces many dynamic company profiles. These are all displayed by one jsp page with a parameter that identifies the company.

I am no expert on SEO practices but I am certain that a user friendly url would be better for search engines then an obscure parameter.

so instead of

site.com/company.jsp?id=21312

it should probably read

site.com/Country/State/Company_Name 

or something to that effect.

Are there any existing strategies or best practices for producing those url's? My environment is a jsp/servlet tomcat container and I am using a front view controller pattern if that makes any difference.

Here are 2 of my thoughts on how to solve it.

1) When the company profile is saved (backend) a html page is generated with a redirect to the parameterized jsp. This page will be saved in a directory structure that matches the example i gave above. /CountryName/StateName/CompanyName.html

I don't know if search engines will just disregard it since it redirects to another page. I also predict housekeeping could become a problem when company names change or their locations change. So I don't know if this is the best path to take.

2) Somehow have a servlet that interprets the url and redirects accordingly.

So in other words have a servlet named Map (for example) and so a url like : site.com/Map/Country/State/CompanyName will be picked up by the Map servlet and breakdown the url in order to find the page in question.

I dont know if that is even possible by servlets. (Edit : It can be done with Map/*)

If there is any other option I am missing please let me know or if I can improve on one of my existing thoughts.

Many thanks.

Fuzz
  • 906
  • 1
  • 12
  • 24

2 Answers2

1

The REST gives your best practise for web URL.You can check this section for more details.

Also you can learn from some famous REST APIs,e.g. Twitter REST API, Google data API( Google Contacts API as example).

As for Java implementation, JAX-RS is Java API for RESTful Web Services.There are many implementations, such as CXF, RESTEasy, Jersey.

Below sample code gives you a quick idea of how JAX-RS looks like:

// Root resource class
@Path("/employeeinfo")
public class EmployeeInfo {

    // Subresource locator: obtains the subresource Employee
    // from the path /employeeinfo/employees/{empid}
    @Path("/employees/{empid}")
    public Employee getEmployee(@PathParam("empid") String id) {
        // Find the Employee based on the id path parameter
        Employee emp = ...;
        ...
        return emp;
    }
}
Wenbing Li
  • 12,289
  • 1
  • 29
  • 41
  • Thank you for your response. That does seem to be the correct way to do things from the start. I am just a little hesitant to implement a web service framework for such a small task. Your answer is very appreciated though. – Fuzz Aug 03 '14 at 05:58
1

Here comes the UrlRewriteFilter !

http://tuckey.org/urlrewrite/

Configuration to do what you asked will look like:

<rule>
  <name>World Rule</name>
  <from>^/world/([a-z]+)/([a-z]+)$</from>
  <to>/world.jsp?country=$1&amp;city=$2</to>
</rule>

http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html

Alex Chernyshev
  • 1,719
  • 9
  • 11
  • This is fantastic. and I already have urlRewriteFilter implemented for a sub domain redirect. However, do you know what the advantage of this is over having a servlet map to World/* for example then using the request URI to breakdown where it came from? Convenience mostly? – Fuzz Aug 03 '14 at 05:56
  • 1
    Pattern support for servlet bindings is very limited, for example you cannot bind servet to url and extract part of url path as parameter to simulate RESTful url. Here is brief info about what you can do with url-pattern http://www.roguewave.com/portals/0/products/hydraexpress/docs/3.5.0/html/rwsfservletug/4-3.html and http://stackoverflow.com/questions/8570805/can-we-user-regular-expression-type-patterns-in-web-xml – Alex Chernyshev Aug 03 '14 at 06:19