Note that there are some explanatory texts on larger screens.

plurals
  1. POBest practices of implementation of front controller using java servlets
    text
    copied!<p>Suppose we have some project with next structure: </p> <pre> web articles main.jsp sidearts.jsp central.jsp forum main.jsp css js WEB-INF web.xml </pre> <p>Note that we don't have front controller at this point yet.</p> <p>After deploying with some facet (let it be 'asdf') we can access our pages using next URLs:</p> <pre> http://localhost:8080/asdf/articles/main.jsp http://localhost:8080/asdf/forum/main.jsp and so on.. </pre> <p>main.jsp generates some html and includes sidearts.jsp (by means of jstl c:import or any other way)</p> <p>And what will happen after adding front controller?</p> <p>Suppose we have servlet ArticlesController which is responsible for dispatching <br> some requests and which has next mapping: </p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;ArtsController&lt;/servlet-name&gt; &lt;servlet-class&gt;org.forstackoverflow.ArticlesController&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;ArtsController&lt;/servlet-name&gt; &lt;url-pattern&gt;/articles/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Now when we request URL <code>http://localhost:8080/asdf/articles/main</code>, ArticlesController handles this request and try to include articles/main.jsp. And at this point infinity cycle starts because /articles/* is mapped to ArtsController.</p> <p>What is the correct solution of described problem?</p> <p>My variants are:</p> <p>1) make mappings for all jsp-files (I don't think that it is acceptible)</p> <p>2) change directories names (articles->arts); but then we get lots of new URLs (like <code>http://localhost:8080/asdf/arts/main.jsp</code>) and I think that it can be a source of bugs. </p>
 

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