Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your question, you want to have a Java EE site like <code>myrecruitingsite.com</code> where you can redirect a user to <code>myrecruitingsite.com/main/&lt;username&gt;</code>. When a request is made to <code>myrecruitingsite.com/main/arg21</code>, or <code>myrecruitingsite.com/main/geoffreywiseman</code>, you'd want the request to go to the same servlet, and you'd like to know which username was requested.</p> <p>Java servlet mappings don't directly support complex routing patterns in the way that many modern web frameworks do. You can't configure the web.xml to send a request from <code>myrecruitingsite.com/main/&lt;username&gt;</code> to the user profile servlet and <code>myrecruitingsite.com/main/&lt;username&gt;/contact</code> to the contact servlet. You can do wildcard mappings, but all the routing decisions after that you'll have to do outside of the <code>web.xml</code>.</p> <p>Alternately, you can do <a href="http://en.wikipedia.org/wiki/Rewrite_engine" rel="nofollow">URL rewriting</a> (typically with servlet filters) such that the URL requested by the browser is not the final one interpreted by the servlet mapping layer. There are frameworks for this, or you can do it yourself.</p> <p>Basically, you need to configure the <a href="http://docs.oracle.com/cd/E13222_01/wls/docs92/webapp/configureservlet.html" rel="nofollow">servlet mapping</a>'s url pattern with a wildcard, and then query <a href="http://docs.oracle.com/javaee/1.2.1/api/javax/servlet/http/HttpServletRequest.html#getPathInfo%28%29" rel="nofollow">getPathInfo()</a> to find out what the rest of the wildcard was. That alone is pretty simple.</p> <p>If you're using any one of a wide array of Java web frameworks, there will be facilities for routing and quite possibly a front controller servlet that does what you need already. In that scenario, you'll need to look at the framework's documentation for more information.</p> <p>On the other hand, if you're doing it yourself using servlets (or even servlets + jsp), you can either just do a wildcard mapping to a single servlet that will grow larger and larger as you add more features to it, or more likely, you'll need to develop your own micro-framework where the servlet acts as a <a href="http://martinfowler.com/eaaCatalog/frontController.html" rel="nofollow">Front Controller servlet</a> and does the routing work and delegates all the subsequent work to plain old java objects (POJOs).</p> <p>By way of example, your routing servlet could maintain a mapping between url patterns (perhaps specified in java regular expressions) to objects of your own creation that either mimic the servlet interface or another interface of your own creation. That way, you have a servlet that's responsible for the routing decisions bound in the web.xml, and a network of little classes that are responsible for the specifics of a particular request. It's work, but it's not terrifically difficult.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload