Skip to main content

Write a JSP which insert the details of the 3 or 4 users who register with the web site by using registration form. Authenticate the user when he submits the login form using the user name and password from the database

Write a JSP which does the following job
 Insert the details of the 3 or 4 users who register with the web site (week9) by using registration form. Authenticate the user when he submits the login form using the user name and password from   the database (similar to week8 instead of cookies).

Description

JSP scripting elements let you insert Java code into the servlet that will be generated from the current JSP page. There are three forms:
  1. Expressions of the form <%= expression %> that are evaluated and inserted into the output,
  2. Scriptlets of the form <% code %> that are inserted into the servlet's service method, and
  3. Declarations of the form <%! code %> that are inserted into the body of the servlet class, outside of any existing methods.
Each of these is described in more detail below.

JSP Expressions

A JSP expression is used to insert Java values directly into the output. It has the following form:
               <%= Java Expression %>
The Java expression is evaluated, converted to a string, and inserted in the page. This evaluation is performed at run-time (when the page is requested), and thus has full access to information about the request. For example, the following shows the date/time that the page was requested:
               Current time: <%= new java.util.Date() %>
To simplify these expressions, there are a number of predefined variables that you can use. These implicit objects are discussed in more detail later, but for the purpose of expressions, the most important ones are:
  • request, the HttpServletRequest;
  • response, the HttpServletResponse;
  • session, the HttpSession associated with the request (if any); and
  • out, the PrintWriter (a buffered version of type JspWriter) used to send output to the client.

JSP Scriptlets

If you want to do something more complex than insert a simple expression, JSP scriptlets let you insert arbitrary code into the servlet method that will be built to generate the page. Scriptlets have the following form:
               <% Java Code %>
Scriptlets have access to the same automatically defined variables as expressions. So, for example, if you want output to appear in the resultant page, you would use the out variable.
<% 
String queryData = request.getQueryString();
out.println("Attached GET data: " + queryData); 
%>
               Note that code inside a scriptlet gets inserted exactly as written, and any static HTML (template text) before or after a scriptlet gets converted to print statements. This means that scriptlets need not contain complete Java statements, and blocks left open can affect the static HTML outside of the scriptlets. 

JSP Declarations

A JSP declaration lets you define methods or fields that get inserted into the main body of the servlet class (outside of the service method processing the request). It has the following form:
<%! Java Code %>
Since declarations do not generate any output, they are normally used in conjunction with JSP expressions or scriptlets. For example, here is a JSP fragment that prints out the number of times the current page has been requested since the server booted (or the servlet class was changed and reloaded):
<%! private int accessCount = 0; %>
PROGRAM:
Login.html:
<!--Home.html-->
<html> <body>
<center><h1>XYZ Company Ltd.</h1></center>
<table border="1" width="100%" height="100%">
<tr>
            <td valign="top" align="center"><br/>
                                    <form action="auth.jsp"><table>
                                    <tr>
                                         <td colspan="2" align="center"><b>Login Page</b></td>
                                    </tr>
                                    <tr>
                                         <td colspan="2" align="center"><b>&nbsp;</td>
                                    </tr>
                                    <tr>
                                           <td>User Name</td>
                                           <td><input type="text" name="user"/></td>
                                    </tr>
                                    <tr>
                                           <td>Password</td>
                                              <td><input type="password" name="pwd"/></td>
                                    </tr>
                                    <tr>
                                              <td>&nbsp;</td>
                                              <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                       <td colspan="2" align="center"><input type="submit" value="LogIN"/></td>
                                    </tr>
                                    </table>
                                    </form>
            </td>
</tr>
</table>
</body>
</html>
Auth.jsp:
<%@page import="java.sql.*;"%>
<html>
<head>
<title>
This is simple data base example in JSP</title>
</title>
</head>
<body bgcolor="yellow">
<%!String uname,pwd;%>
<%
uname=request.getParameter("user");
pwd=request.getParameter("pwd");
  try
{
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection con=DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:1521:CCLAB","scott","tiger");
  Statement st=con.createStatement();
  ResultSet rs=st.executeQuery("select name,password from personal where name='"+uname+"' and password='"+pwd+"'");
  if(rs.next())
{
out.println("Authorized person");
}
else
{
out.println("UnAuthorized person");
}
con.close();
}
catch(Exception e){out.println(""+e);}
%>
</body>
</html>
OUTPUT:

http://wikibrand.blogspot.in
http://wikibrand.blogspot.in
http://wikibrand.blogspot.in
RESULT:

The user is authenticated when he submits the login form using the user name and password from   the database.

Comments

Popular posts from this blog

Create a socket for HTTP for web page upload and download

Create a socket for HTTP for web page upload and download. Aim: To write a java program for socket for HTTP for web page upload and download . Algorithm 1.Start the program. 2.Get the frame size from the user 3.To create the frame based on the user request. 4.To send frames to server from the client side. 5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client. 6.Stop the program Program : Client import javax.swing.*; import java.net.*; import java.awt.image.*; import javax.imageio.*; import java.io.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Client{ public static void main(String args[]) throws Exception{ Socket soc; BufferedImage img = null; soc=new Socket("localhost",4000); System.out.println("Client is running. ");  try { System.out.println("Reading image from disk. "); im...

Write an HTML program to design an entry form of student details and send it to store at database server like SQL, Oracle or MS Access

Write an HTML program to design an entry form of student details and send it to store at database server like SQL, Oracle or MS Access <!DOCTYPE html> <html> <head> <title>PHP insertion</title> <link href="css/insert.css" rel="stylesheet"> </head> <body> <div class="maindiv"> <!--HTML Form --> <div class="form_div"> <div class="title"> <h2>Insert Data In Database Using PHP.</h2> </div> <form action="insert.php" method="post"> <!-- Method can be set as POST for hiding values in URL--> <h2>Form</h2> <label>Name:</label> <input class="input" name="name" type="text" value=""> <label>Email:</label> <input class="input" name="email" type="text" value=""> <label>Contact:</label> <inp...

Write a code simulating PING and TRACEROUTE commands

  Write a code simulating PING command     Aim:   To Write the java program for simulating ping command   Algorithm Step 1: start the program. Step 2: Include necessary package in java. Step 3: To create a process object p to implement the ping command. Step 4: declare one BufferedReader stream class object. Step 5: Get thedetails of the server          5.1: length of the IP address.          5.2: time required to get the details.          5.3: send packets , receive packets and lost packets.          5.4: minimum ,maximum and average times. Step 6: print the results. Step 7:Stop the program.   Program:   import java.io.*; import java.net.*; class pingserver { public static void main(String args[]) { try { String str; System.out.print(" Enter...