Typically, when you develop a web application when you install it in a servlet container (in your case glassfish) you define the application root that maps URL's to your web-app.
If you use /myapp as application root, the container will map requests to http://mysite.com/myapp/*
to your web-app. Servlets in the web-app are mapped in the web.xml
in which you map servlet class.
If you say, map the servlet com.mysite.UserServlet
to user
the container will map all URL's of the format http://mysite.com/myapp/user*
to that servlet. You can use the pathinfo
to retrieve the part after /myapp/user
and parse it to extract the username in case you chose to use URL's like http://mysite.com/myapp/user/Sam
instead of http://mysite.com/myapp/user?name=Sam
Edit
The method HttpServletRequest.getPathInfo() (quote) returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string. This method returns null if there was no extra path information.
So for http://mysite.com/myapp/user/Sam
and a servlet mapped to /user/
getPathInfo() would return Sam
, which you can then use just like you would if you got the value as attribute.
For this, your web.xml
would contain a mapping like:
<web-app>
<servlet>
<servlet-name>userservlet</servlet-name>
<servlet-class>com.mysite.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>userservlet</servlet-name>
<url-pattern>/user/</url-pattern>
</servlet-mapping>
</web-app>