i’m trying to implement a basic mvc pattern for a java web app project in netbeans. i have the deployment descriptor (web.xml) correct but i can’t seem to redirect to the correct jsp from the java servlet itself. here’s the directory of my project folder:
/project
/src
/conf
MANIFEST.MF
/java
/ph
/com
/client
/esurvey
/objects
/* other .java files */
/servlets
ManageSurveysServlet.java
/* other .java files */
/build
/empty
/web
index.jsp
manage_surveys.jsp
script.js
style.css
/META-INF
context.xml
MANIFEST.MF
/WEB-INF
web.xml
/classes
.netbeans_update_resources
.netbeans_automatic_build
/ph
/com
/client
/esurvey
/objects
/* .class files found here */
/servlets
ManageSurveysServlet.class
/* other .class files found here */
a link from index.jsp calls the ManageSurveysServlet which in turn forwards a request object and redirects to manage_surveys.jsp, but given the above directories, i don’t know what path/filename to use to reference manage_surveys.jsp with from the servlet. here’s the code in the servlet that forwards the request object:
request.setAttribute("surveys", surveys); // surveys is an arraylist
RequestDispatcher dispatcher = request.getRequestDispatcher("manage_surveys.jsp"); // i'm guessing it can't find the jsp
dispatcher.forward(request, response);
UPDATE: web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>ManageSurveysServlet</servlet-name>
<servlet-class>ph.com.client.esurvey.servlets.ManageSurveysServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ManageSurveysServlet</servlet-name>
<url-pattern>/ManageSurveys</url-pattern>
</servlet-mapping>
<session-config><session-timeout>30</session-timeout></session-config>
<welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>
</web-app>
Move
manage_surveys.jspintoWEB-INFfolder.I think that will be solution.