11. Develop a JSP Application to accept Registration Details from the user and store database table.


 <%-- 
    Document   : login
    
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
        <title>Register Page</title>
       
        
    </head>
    <body>
        
        <center><h1> <b><u>Register Here</u></b></h1><hr>
            <form action="r1.jsp"><table><b>
           <br> <tr><td>Name</td><td><input type="text" name="name"></td></tr>
            <br><tr><td>User ID</td><td><input type="text" name="id"></td></tr>
            <br><tr><td>Password</td><td><input type="password" name="password"></td></tr>
            <br><tr><td>Date of Birth</td><td><input type="text" name="date"></td></tr>
            <br><tr><td>Address</td><td><textarea name="address"></textarea></td></tr>
                <br>
                <tr><td> <input type="submit" value="Register"></td></tr></b></table>
                    </form>
            <br><hr>
              Already Registered!! To Login <a href="login.jsp">Click Here</a>
                <hr>
                
    </center>
    
    
    </body>
</html>



<%-- 
    Document   : r1
    
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <%@ page language="java" %>
        <%@ page import="java.sql.*" %>
         <%@ page import="java.sql.DriverManager.*" %>
       
        <%
        String m=null, mn=null;
        String s=request.getParameter("name");
        String s1=request.getParameter("id");
        String s2=request.getParameter("password");
        String s3=request.getParameter("date");
        String s4=request.getParameter("address");
        PreparedStatement ps;
        Connection con;
        ResultSet rs= null;
       Class.forName("oracle.jdbc.driver.OracleDriver");
        con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");
      
         Statement st=con.createStatement();
       
          ps= con.prepareStatement("insert into register values (?,?,?,?,?)");
            ps.setString(1,s);
            ps.setString(2, s1);
            ps.setString(3,s2);
            ps.setString(4,s3);
            ps.setString(5,s4);
           
               int insertResult = ps.executeUpdate();
             if (insertResult!=0)
            {
                 out.println("Successfully registered");
               
            }
    
         
           
        %>
        <br><hr>
               To Login <a href="login.jsp">Click Here</a>
                <hr>
          
    </body>
</html>



create table register(
name varchar2(20),
id varchar2(20),
password varchar2(10),
dated varchar2(10),
address varchar2(30),
primary key(id));
);




9. Write a simple JSP application to demonstrate the use of implicit object (at least 5).

<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<%@ page import="java.util.Date" %>
<!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=US-ASCII">
<title>Index JSP Page</title>
</head>
<body>
<%-- out object example --%>
<h4>Hi There</h4>
<strong>Current Time is</strong>: <% out.print(new Date()); %><br><br>

<%-- request object example --%>
<strong>Request User-Agent</strong>: <%=request.getHeader("User-Agent") %><br><br>

<%-- response object example --%>
<%response.addCookie(new Cookie("Test","Value")); %>

<%-- config object example --%>
<strong>User init param value</strong>:<%=config.getInitParameter("User") %><br><br>

<%-- application object example --%>
<strong>User context param value</strong>:<%=application.getInitParameter("User") %><br><br>

<%-- session object example --%>
<strong>User Session ID</strong>:<%=session.getId() %><br><br>

<%-- pageContext object example --%>
<% pageContext.setAttribute("Test", "Test Value"); %>
<strong>PageContext attribute</strong>: {Name="Test",Value="<%=pageContext.getAttribute("Test") %>"}<br><br>

<%-- page object example --%>
<strong>Generated Servlet Name</strong>:<%=page.getClass().getName() %>

</body>
</html>

8. b. Create a JSP page to print current date and time

<%@ page import="java.io.*,java.util.*, javax.servlet.*" %>
<html>
<head>
<title>Display Current Date & Time</title>
</head>
<body>
<center>
<h1>Display Current Date & Time</h1>
</center>
<%
   Date date = new Date();
   out.print( "<h2 align=\"center\">" +date.toString()+"</h2>");
%>
</body>
</html>

8. JSP Programs a. Create a JSP page that prints temperature conversion (from Celsius to Fahrenheit) chart

<%@ page session="false" %>
<table border="0" align="center" width="50%">
<tr>
   <th align="right">Celsius</th>
   <th align="right">Fahrenheit</th>
</tr>
<%
   for (int c = 0; c <= 100; c += 10) {
      int f = 32 + 9*c/5;
      out.print("<tr>");
      out.print("<td align=\"right\">" + c + "</td>");
      out.print("<td align=\"right\">" + f + "</td>");
      out.print("</tr>");
   }
%>
</table>

7. Develop Servlet application to accept HTNO of a student from client and display the memorandum of marks from the server

STUDENT MARKLIST USING SERVLET
AIM:
To create a three tier application for displaying the student marklist.
ALGORITHM:
Client:
Step1: In index.html on the client side declare the contents that you like to transfer to the
server using html form and input type tags.
Step2: create a submit button and close all the included tags.
Servlet:
Step 1: Import all necessary packages
Step 2: Define a class that extends servlet
Step 3: In the doPost() method, do the following:
i) Set the content type of the response to "text/html"
ii) connect with the database which has the student marklist
iii) query the data to the database
Step 4: Display the student marklist.
PROGRAM:
SERVLET CODE:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class serv extends HttpServlet
{
String message,Reg_no;
Connection connect;
Statement stmt=null; ResultSet
rs=null;
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
try
{
String url="jdbc:odbc:NEO";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connect=DriverManager.getConnection(url," "," "); message="Mark List";
}
catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();
}
catch(SQLException sqlex)
{
sqlex.printStackTrace();
}
catch(Exception excp)
{
excp.printStackTrace();
}
Reg_no=request.getParameter("regno");
response.setContentType("text/html"); PrintWriter
out=response.getWriter(); out.println("<html>");
out.println("<head>"); out.println("</head>");
out.println("<body bgcolor=cyan>");
out.println("<center>");
out.println("<h1>"+message+"</h1>\n");
try
{
Statement stmt=connect.createStatement();
String query=new String("SELECT * FROM MarkList WHERE regno= "+Reg_no);
rs=stmt.executeQuery(query);
boolean b=rs.next();
out.println("Regsitration No:"+rs.getInt(1)); out.println("<br>"+"Name:"+rs.getString(2));
out.println("<table
border=5>"); out.println("<th>"+"cs01"+"</th>"); out.println("<th>"+"cs02 "+"</th>");
out.println("<th>"+"cs03"+"</th>"); out.println("<th>"+"status"+"</th>");
while(b)
{
out.println("<tr>"); out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(4)+"</td>");
out.print("<td>"+rs.getString(5)+"</td>");
out.print("<td>"+rs.getString(6)+"</td>"); out.println("</tr>");
b=rs.next();
}
out.println("</table>");
}
catch(SQLException ex){
out.println("error in connection");
}
finally
{
try
{ if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(connect!=null)
connect.close();
}
catch(SQLException e){ }
}
out.println("</center>");
out.println("</body></html>");
}
}
HTML CODE:
<html>
<head><title> mark sheet</title></head>
<body><center>
<h1>Student Mark Sheet</h1>
</center><form action="serv" method="POST">
registration number:<input type="text" name="regno">
<input type="submit" value="Submit"><br><br>
</form></body></html>
OUTPUT:
Result:
Thus the given program was coded and executed successfully

3. Create GUI to demonstrate swing components using student registration form.

Registration.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class Registration extends JFrame implements ActionListener
  {
    JLabel l1, l2, l3, l4, l5, l6, l7, l8;
    JTextField tf1, tf2, tf5, tf6, tf7;
    JButton btn1, btn2;
    JPasswordField p1, p2;

    Registration()
     {
        setVisible(true);
        setSize(700, 700);
        setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Registration Form in Java");

        l1 = new JLabel("Registration Form in Windows Form:");
        l1.setForeground(Color.blue);
        l1.setFont(new Font("Serif", Font.BOLD, 20));

        l2 = new JLabel("Name:");
        l3 = new JLabel("Email-ID:");
        l4 = new JLabel("Create Passowrd:");
        l5 = new JLabel("Confirm Password:");
        l6 = new JLabel("Country:");
        l7 = new JLabel("State:");
        l8 = new JLabel("Phone No:");
        tf1 = new JTextField();
        tf2 = new JTextField();
        p1 = new JPasswordField();
        p2 = new JPasswordField();
        tf5 = new JTextField();
        tf6 = new JTextField();
        tf7 = new JTextField();

        btn1 = new JButton("Submit");
        btn2 = new JButton("Clear");

        btn1.addActionListener(this);
        btn2.addActionListener(this);

        l1.setBounds(100, 30, 400, 30);
        l2.setBounds(80, 70, 200, 30);
        l3.setBounds(80, 110, 200, 30);
        l4.setBounds(80, 150, 200, 30);
        l5.setBounds(80, 190, 200, 30);
        l6.setBounds(80, 230, 200, 30);
        l7.setBounds(80, 270, 200, 30);
        l8.setBounds(80, 310, 200, 30);
        tf1.setBounds(300, 70, 200, 30);
        tf2.setBounds(300, 110, 200, 30);
        p1.setBounds(300, 150, 200, 30);
        p2.setBounds(300, 190, 200, 30);
        tf5.setBounds(300, 230, 200, 30);
        tf6.setBounds(300, 270, 200, 30);
        tf7.setBounds(300, 310, 200, 30);
        btn1.setBounds(50, 350, 100, 30);
        btn2.setBounds(170, 350, 100, 30);

        add(l1);
        add(l2);
        add(tf1);
        add(l3);
        add(tf2);
        add(l4);
        add(p1);
        add(l5);
        add(p2);
        add(l6);
        add(tf5);
        add(l7);
        add(tf6);
        add(l8);
        add(tf7);
        add(btn1);
        add(btn2);
    }

    public void actionPerformed(ActionEvent e)
     {
        if (e.getSource() == btn1)
         {
            int x = 0;
            String s1 = tf1.getText();
            String s2 = tf2.getText();

            char[] s3 = p1.getPassword();
            char[] s4 = p2.getPassword();
            String s8 = new String(s3);
            String s9 = new String(s4);

            String s5 = tf5.getText();
            String s6 = tf6.getText();
            String s7 = tf7.getText();
            if (s8.equals(s9))
           {
                try
               {
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "sandeep", "welcome");
                    PreparedStatement ps = con.prepareStatement("insert into reg values(?,?,?,?,?,?)");
                    ps.setString(1, s1);
                    ps.setString(2, s2);
                    ps.setString(3, s8);
                    ps.setString(4, s5);
                    ps.setString(5, s6);
                    ps.setString(6, s7);
                    ResultSet rs = ps.executeQuery();
                    x++;
                    if (x > 0)
                    {
                        JOptionPane.showMessageDialog(btn1, "Data Saved Successfully");
                    }
                }
          catch (Exception ex)
                {
                    System.out.println(ex);
                }
            }
          else
           {
                JOptionPane.showMessageDialog(btn1, "Password Does Not Match");
            }
        }
          else
       {
            tf1.setText("");
            tf2.setText("");
            p1.setText("");
            p2.setText("");
            tf5.setText("");
            tf6.setText("");
            tf7.setText("");
        }
    }
    public static void main(String args[])
   {
        new Registration();
    }
}
Note

You need to add a JAR file named "ojdbc.jar" to set up the database connection.

2. Create GUI to demonstrate typical Editable Table which describing Employee for a software company.