Redirecting servlet to another html page



I have two html pages - one for login and one that takes in a persons details. The login page is the first page and when the database is checked for the username and password, the user is allowed to enter their details. The SQL code works perfectly, it is just a problem with the mapping I am having. Could anybody help or spot what i am doing wrong?


This is my java code for logging in and entering details



public class Details extends HttpServlet {

private Connection con;

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

res.setContentType("text/html");
//return writer
PrintWriter out = res.getWriter();

String username = req.getParameter("username");
String password = request.getParameter("password");

out.close();

try {
login(username, password);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

res.sendRedirect("/redirect.html");

//get numbers from form
String name = request.getParameter("name");
String address = request.getParameter("address");
String age = request.getParameter("age");

out.println("<HTML><HEAD><TITLE>Personnel Details</TITLE></HEAD><BODY>");
out.println(name + address + age);
out.println("</BODY></HTML>");
System.out.println("Finished Processing");
}

out.close();


}


In my web.xml file I have:



<web-app>

<servlet>
<servlet-name>Details</servlet-name>
<servlet-class>Details</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Details</servlet-name>
<url-pattern>/Details</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>redirect</servlet-name>
<url-pattern>/redirect</url-pattern>

No comments:

Post a Comment