0

I would like to be able to receive a request on a servlet I made, then analyse the URL and configure the application database based on that, and after the DB is configure forward the request to the regular Faces Servlet.

How should I configure my web.xml? And how can I forward the request to the Faces Servlet?

Here is what I was thinking:

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>aws</servlet-name>
        <servlet-class>servlets.aws</servlet-class>
    </servlet>
<!--    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>-->
    <servlet-mapping>
        <servlet-name>aws</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    System.out.println("configure DB based on URL");

    RequestDispatcher rd = request.getRequestDispatcher("FacesServlet");
    rd.forward(request, response);        
}

However that gives the following error:

enter image description here

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Alexandre Krabbe
  • 727
  • 1
  • 13
  • 33
  • https://stackoverflow.com/questions/3024949/how-do-i-execute-multiple-servlets-in-sequence. – Kukeltje Sep 17 '19 at 17:59
  • Based on the answer of that question I was not able to figure out what I have to do, more specifically how should I configure my web.xml? Sorry if this seems like a silly question but I'm pretty new to servlets and JSF. – Alexandre Krabbe Sep 17 '19 at 18:12
  • Isn't there a space missing in "FacesServlet"? `request.getRequestDispatcher("FacesServlet");` – Selaron Sep 17 '19 at 18:33
  • @Selaron: it is wrong anyway iirc. You should not forward to a servlet name (look at the error, there is a relative path in there in front of 'FacesServlet'. You forward to path (that was what I wanted to hint at. I think op needs a filter for his 'aws' code instead of a servlet. Hinted at in another part in the link by talking about independent servlets – Kukeltje Sep 17 '19 at 19:09
  • https://stackoverflow.com/questions/7938138/what-if-url-pattern-matches-multiple-servlets – Kukeltje Sep 17 '19 at 19:21
  • https://stackoverflow.com/questions/2957165/servlet-vs-filter and https://stackoverflow.com/questions/4720942/difference-between-filter-and-listener-in-servlet-java-ee – Kukeltje Sep 17 '19 at 19:27
  • And https://stackoverflow.com/questions/9812664/what-is-the-difference-between-a-servlet-filter-and-a-servlet-context-listener – Kukeltje Sep 17 '19 at 19:33
  • Thank you @Kukeltje – Alexandre Krabbe Sep 17 '19 at 19:47
  • 1
    And? You solved the problem? By using a filter instead of a servlet? – Kukeltje Sep 19 '19 at 17:51
  • Sorry for the delay, yes I was able to solve the problem by following the tips you gave me, thank you! – Alexandre Krabbe Sep 19 '19 at 21:15

0 Answers0