web.xml izgleda ovako:
Code:
<servlet-mapping>
<servlet-name>FrontControler</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FrontControler</servlet-name>
<url-pattern>/pages/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FrontControler</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FrontControler</servlet-name>
<url-pattern>/pages/*</url-pattern>
</servlet-mapping>
Deo servleta koji obradjuje zahteve:
Code:
String uri=request.getRequestURI();
getServletContext().log("Request URI: "+uri);
uri=uri.substring(request.getContextPath().length());
getServletContext().log("Striped context: "+uri);
if(uri==null || uri.trim().equals("") ||uri.equals("/")){
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/main. jsp");
rd.forward(request, response);
}
else{
RequestDispatcher rd=getServletContext().getRequestDispatcher(uri);
rd.forward(request, response);
}
String uri=request.getRequestURI();
getServletContext().log("Request URI: "+uri);
uri=uri.substring(request.getContextPath().length());
getServletContext().log("Striped context: "+uri);
if(uri==null || uri.trim().equals("") ||uri.equals("/")){
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/main. jsp");
rd.forward(request, response);
}
else{
RequestDispatcher rd=getServletContext().getRequestDispatcher(uri);
rd.forward(request, response);
}
Kada je URL "localhost:8080/frontcontroler", uredno se prikaze main.jsp, i to je OK. Ali, na toj strani je link ka pages/lnk.html", i kada kliknem na njega, izgleda da upadnem u neku vrstu petlje, i Tomcat na kraju prijavi StackOverflowError. Deo log fajla Tomcat-a:
Code:
2004-06-25 12:05:12 StandardContext[/frontcontroler]Request URI: /frontcontroler/
2004-06-25 12:05:12 StandardContext[/frontcontroler]Striped context: /
2004-06-25 12:05:29 StandardContext[/frontcontroler]Request URI: /frontcontroler/pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Striped context: /pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Request URI: /frontcontroler/pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Striped context: /pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Request URI: /frontcontroler/pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Striped context: /pages/lnk.html
2004-06-25 12:05:12 StandardContext[/frontcontroler]Request URI: /frontcontroler/
2004-06-25 12:05:12 StandardContext[/frontcontroler]Striped context: /
2004-06-25 12:05:29 StandardContext[/frontcontroler]Request URI: /frontcontroler/pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Striped context: /pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Request URI: /frontcontroler/pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Striped context: /pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Request URI: /frontcontroler/pages/lnk.html
2004-06-25 12:05:29 StandardContext[/frontcontroler]Striped context: /pages/lnk.html
i tako u nedogled. Probao sam da debagujem, ali nista ne mogu da skontam, sve izgleda OK, pa mi se cini da je greska u deploymnet descriptoru, ali i tu mi se sve cini OK. Ali kao da servlet prosledjuje zahteve sam sebi?
Ako moze neki savet....