MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

Java Servlet Programing Laungage

Java Servlet Projects

Servlet Project 3

Java Servlet :Example of RequestDispatcher
Previous Home Next

Example of RequestDispatcher

RequestDispatcher object is used by the servlet to forward the request to another web resource to include the contents of another web resource.

LoginServlet.java

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet
{
 public void doGet(HttpServletRequest request,HttpServletResponse response)
         throws ServletException,IOException
 {
 try
 {
   String user1=request.getParameter("txtName");
   String password1=request.getParameter("txtPassword");
   response.setContentType("text/html");
   PrintWriter out=response.getWriter();
   Class.forName("oracle.jdbc.driver.OracleDriver");
   Connection con=DriverManager.getConnection
	     ("jdbc:oracle:thin:@localhost:1521:xe","system","gaurav");
   PreparedStatement stmt=con.prepareStatement
	     ("select * from infologin where name=? and password=?");
   stmt.setString(1,user1); 
   stmt.setString(2,password1);
   ResultSet rset=stmt.executeQuery();
   if(rset.next())
   out.println("Welcome," +user1);
  else
  {
    out.println("<b>Invalid username and password !</b><br>");
    RequestDispatcher rd=request.getRequestDispatcher("index.html");
    rd.include(request,response);
  }
out.close();con.close();
}
  catch(Exception e)
{
	  System.out.println(e);
}
}
}

 

index.html

<html>
	<head>
	  <title> third web applicatin</title>
	</head>
	<body>
	  <form method="get" action="loginServlet">
	  Name<input type="text" name="txtName"> <br>
	  Password<input type="password" name="txtPassword">
	  <input type="submit" value="submit">
	  </form>
	</body>
</html>

web.xml

<web-app>
	<servlet>
	  <servlet-name> v1 </servlet-name>
	  <servlet-class> LoginServlet </servlet-class>
	</servlet>
	<servlet-mapping>
	  <servlet-name> v1 </servlet-name>
	  <url-pattern> loginServlet </url-pattern>
	</servlet-mapping>
</web-app>
Previous Home Next