java - redirects not working in jsp -


i have created jsp page view.jsp , corresponding have created servlet admin.java code of both below... when click on register blank page appears...redirects not working. please me in resolving

view.jsp

 <%@ page language="java" contenttype="text/html; charset=iso-8859-1"     pageencoding="iso-8859-1"%>     <!doctype html public "-//w3c//dtd html 4.01 transitional//en"                     "http://www.w3.org/tr/html4/loose.dtd">     <html>     <head>     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">     <title>insert title here</title>     </head>     <body>     <form action="admin">     username <input type="text" name="username" value="" />     password <input type="text" name="password" value="" />     <input type="submit" name="register" value="register" />"     </form>     </body>     </html>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  admin.java     import java.io.*;       import java.sql.*;       import javax.servlet.*;     import javax.servlet.http.*;       public class admin extends httpservlet {      static final string jdbc_driver = "com.mysql.jdbc.driver";     static final string db_url = "jdbc:mysql://localhost:3306/inventory";     static final string user = "root";     static final string pass = "root";       connection conn = null;     statement stmt = null;      public void doget(httpservletrequest req, httpservletresponse res)     throws servletexception, ioexception {        try {      string user = req.getparameter("username");     string pass = req.getparameter("password");       class.forname("com.mysql.jdbc.driver");     conn = drivermanager.getconnection(db_url, user, pass);     stmt = conn.createstatement();     string sql = "select * admins";     //string sql = "select * admins username='"+user+"' ,           password='"+pass+"'";     resultset rs = stmt.executequery(sql);       printwriter pw = res.getwriter();     //res.setcontenttype("text/html");        while (rs.next())      {     if((user.equals(rs.getstring(0))) &&  (pass.equals(rs.getstring(1))))     {     //string n=rs.getstring("username");     //string p=rs.getstring("password");     res.sendredirect("loginsuccess.jsp");      }     else      {     res.sendredirect("loginfailure.jsp");     }     }      pw.close();      } catch (classnotfoundexception e) {     // todo auto-generated catch block     e.printstacktrace();     } catch (sqlexception e) {     // todo auto-generated catch block     e.printstacktrace();     }      }      } 

use requestdispatcher instead of sendredirect():

requestdispatcher reqdispatcher = req.getrequestdispatcher("path/loginsuccess.jsp");             reqdispatcher.forward(req, res); 

read more requestdispatcher.

read difference between requestdispatcher , sendredirect, , whento use both of them.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -