java - Redirecting servlet to another html page -
i have 2 html pages - 1 login , 1 takes in persons details. login page first page , when database checked username , password, user allowed enter details. sql code works perfectly, problem mapping having. using tomcat server way. or spot doing wrong?
this java code logging in , 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"); 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 web.xml file 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>
you may try :
response.sendredirect("redirect.html");
or
response.setstatus(response.sc_moved_temporarily); response.setheader("location", "redirect.html");
alternative way,
servletcontext sc = getservletcontext(); sc.getrequestdispatcher("/redirect.html").forward(request, response);
Comments
Post a Comment