© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

Send Redirect Using Java

Description:

In this program whenever the client makes any request it goes to the container, there the container decides whether the concerned servlet can handle the request or not. If not then the servlet decides that the request can be handle by other servlet or jsp. Then the servlet calls the sendRedirect () method of the response object and sends back the response to the browser along with the status code. Then the browser sees the status code and look for that servlet which can now handle the request. Again the browser makes a new request, but with the name of that servlet which can now handle the request and the result will be displayed to you by the browser.

In this example we are having one jsp page in which we will submit the user name and his password. The controller will check if the username and password entered by the user is correct or not. If the password entered by the user is correct then the servlet will redirect the request to the other jsp which will handle the request. If the password entered by the user is wrong then the request will be forwarded to the jsp form which has some error message.

Send Redirect Using Java :

/*admin.jsp*/
Warning: ob_start() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in /home/content/22/4814422/html/Send_Redirect/index.php on line 72
New Page 1

Admin Login Form



Name          : 

Password  :  



/*invalid1a.jsp*/
Warning: ob_start() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in /home/content/22/4814422/html/Send_Redirect/index.php on line 109
New Page 1




Enter Correct Values ...





/*admincheck.jsp*/ <%@ page import="java.sql.*"%> <% int i=0; String uname=request.getParameter("T1"); String upass=request.getParameter("T2"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:banks"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select user,pass from admin"); while(rs.next()){ String g1=rs.getString("user"); String g2=rs.getString("pass"); if(uname.equals(g1) & upass.equals(g2)){ response.sendRedirect("work_admin.jsp"); i=1; } } if(i!=1){ response.sendRedirect("invalid1a.jsp"); } %> /*work_admin.jsp*/


Administrator Form

                                                                                                                                                                  


Add User

Delete User

Modify User

Admin Console

View Log File

Back

Sample ScreenShot:

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom