I have a Controller Servlet that has to forward a request to a specific JSP. However, whenever I forward the request it loads the JSP but the URL in the browser does something quite strange.
For example:
Via index.jsp
I click: <a href="/login" />
In the Controller I have a method
if(request.getPathInfo().equals("/login"){
dispatcher = this.getServletContext().getRequestDispatcher("/login.jsp");
dispatcher.forward(request, response);
}
The URL in the browser will say:
http://mywebsite.com/my_work/do/login
and not:
http://mywebsite.com/my_work/login.jsp
The login.jsp
page will be shown, just the URL is wrong. This causes problems, as I have to include 2 x References to Javascript and CSS files in each JSP as the relative URL changes depending on if I accessed the page manually by typing http://mywebsite.com/my_work/login.jsp
into the browser, or whether it was accessed via a forward from the Controller servlet.
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>controller.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/do/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<res-ref-name>jdbc/LessonDatabase</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
Any help would be great. I've got everything to work, but I'm guessing that this is not correct!
It should be noted that this occurs for any forwarding.