Pages

Tuesday 29 October 2019

student registration form in html and jsp

--------------------------------
--------------------------------------------
----------------------------------------------------



 student Registration Form(HTML file)


<html>
<head>
<title>student Registration Form</title>
</head><center>
<body>
<h1>student Register Form</h1>
<form action="main.jsp" method="post">
            <table style="with: 50%">
                <tr>
                    <td>First Name</td>
                    <td><input type="text" name="first_name" /></td>
                </tr>
                <tr>
                    <td>Last Name</td>
                    <td><input type="text" name="last_name" /></td>
                </tr>
                <tr>
                    <td>phone</td>
                    <td><input type="text" name="phone" /></td>
                </tr>
                    <tr>
                    <td>Email</td>
                    <td><input type="text" name="email" /></td>
                </tr>
              
                    <tr>
                    <td>gender</td>
                    <td><input type="radio" name="gender" value="male"/>
                    male
                    <input type="radio" name="gender" value="female"/>
                    female</td>
                </tr>
                <tr>
                    <td>branch</td>
                    <td><select name="branch">
                        <option value="mca">mca</option>
                        <option value="ms.c">ms.c</option>
                        <option value="mba">mba</option>
                        </td>
                </tr>
                <tr>
                    <td>Address</td>
                    <td><textarea name="address"></textarea></td>
                </tr>
                </table>
              <h3>  Enter Marks</h3>
        <table style="with: 50%" border="1" >
                <tr >
                    <td>math</td>
                    <td>java</td>
                    <td>ooad</td>
                    <td>itej</td>
                </tr>
                <tr>
                    <td><input type="text" name="math" /></td>
                    <td><input type="text" name="java" /></td>
                    <td><input type="text" name="ooad" /></td>
                    <td><input type="text" name="itej" /></td>
                </tr>
           
      
                </table>
            <input type="submit" value="Submit" /></form></center>
</body>
</html>

student Registration Form(jsp file)

<html>
<head>
<title>student Registration Form</title>
</head><center>
<body>
<h1>student Register Form</h1>
            <table style="with: 50%">
                <tr>
                    <td>First Name</td>
                    <td><%request.getParameter("First_name")%></td>
                </tr>
                <tr>
                    <td>Last Name</td>
                    <td><%request.getParameter("Last_name")%></td>
                </tr>
                <tr>
                    <td>phone</td>
                    <td><%request.getParameter("phone")%></td>
                </tr>
                    <tr>
                    <td>Email</td>
                    <td><%request.getParameter("mail")%></td>
                </tr>
              
                    <tr>
                    <td>gender</td>
                    <td><%request.getParameter("gender")%></td>
                </tr>
                <tr>
                    <td>branch</td>
                    <td><%request.getParameter("branch")%></td>
                </tr>
                <tr>
                    <td>Address</td>
                    <td><%request.getParameter("address")%></td>
                </tr>
                </table>
              <h3>  Enter Marks</h3>
        <table style="with: 50%" border="1" >
                <tr >
                    <td>math</td>
                    <td>java</td>
                    <td>ooad</td>
                    <td>itej</td>
                </tr>
                <tr>
                    <td><%request.getParameter("math")%></td>
                    <td><%request.getParameter("java")%></td>
                    <td><%request.getParameter("ooad")%></td>
                    <td><%request.getParameter("itej")%></td>
                </tr>
           
      
                </table>
            </center>
</body>
</html>

output

 


5 example on jsp

example 1
__________________
<html> <body>
<% out.print("Welcome to KLN JSP Class\n"); %>
</body>
</html>
___________________
example 2
__________________
<html> <body>
<% out.print("Addition Of two number\n"); %>
<br>
<% int a=5, b=10, c; c=a+b;
out.println("Sum of Two Numbers =" + c); %>
</body>
</html>
__________________
example 3
__________________
<html> <body>
<h3> <% String str1 ="Mr. KLN"; %>
<% String str2 =""; %>
Welcome to <%=str1 %> </h3>
<% if(str1.equals("Mr. KLN"))
out.println("Hi "+str1);
else
out.println("Hello ");
%>
</body>
</html>
__________________
example 4
__________________
<html> <body>
<p>Today's date:
<%= (new java.util.Date()).toLocaleString()%>
<br> CLASS Time : <%= 7+2 %> : <%= 20 %>
</p> </body> </html>
__________________
example 5
__________________
<html>
<body>
<%!intdata=50;%>
<%="Valueofthevariableis:"+data%>
</body>
</html>

Monday 28 October 2019

Register

<html> <body>
<center>
<table>
<form action= "servlet/Register" method="post">
<tr> <td> Name: <td><input type="text" name="userName"/><br/><br/>
<tr> <td> Password: <td> <input type="password" name="userPass"/><br/><br/>
<tr> <td> Email Id:<td><input type="text" name="userEmail"/><br/><br/>
<tr> <td> Country: <td>
<select name="userCountry">
<option>India</option>
<option>Pakistan</option>
<option>other</option>
</select>
<br/><br/>
<input type="submit" value="register"/>
</form> </body> </html>



Register.java
88
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
@WebServlet("/servlet/Register")
public class Register extends HttpServlet{
public void doPost(HttpServletRequestrequest, HttpServletResponseresponse)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriterout = response.getWriter();
String n=request.getParameter("userName");
String p=request.getParameter("userPass");
String e=request.getParameter("userEmail");
String c=request.getParameter("userCountry");
Class.forName("oracle.jdbc.driver.OracleDriver");Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system","oracle");PreparedStatementps=con.prepareStatement("insert into registeruservalues(?,?,?,?)");ps.setString(1,n);ps.setString(2,p);ps.setString(3,e);ps.setString(4,c);inti=ps.executeUpdate();if(i>0)out.print("You are successfully registered...");}catch (Exception e2) { System.out.println(e2); }out.close();}}


web.xml
90
<web-app>
<servlet>
<servlet-name>registerpage</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>registerpage</servlet-name>
<url-pattern>/servlet/Register</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Register.html</welcome-file>
</welcome-file-list>
</web-app>


ServletDatabase Connection

importjava.io.*;
importjava.sql.*;
importjavax.servlet.*;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.*;
@WebServlet("/IT2017/DBConnReuse")//XMLfilenotrequired
publicclassDBConnReuseextendsHttpServlet{
privateConnectioncon=null;
publicvoidinit(ServletConfigconfig)throwsServletException
{super.init(config);
try{Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
}catch(Exceptione){System.out.println(e);}}


publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException
{response.setContentType("text/html");
PrintWriterout=response.getWriter();
out.println("<html><body><h1>StudentDetails.</h1>");
Statementstmt;
try{stmt=con.createStatement();
ResultSetrs=stmt.executeQuery("Select*fromstud");
out.println("<html><body>");
while(rs.next())
out.println(rs.getString(1)+""+rs.getString(2));
out.println("</body></html>");
}catch(SQLExceptione){out.println(e);}
}
publicvoiddestroy()
{try{
if(con!=null)con.close();
}catch(Exceptione){System.out.println(e);}
}
}

Login Logout using Cookies

link.html

<html>
<a href="login.html">Login</a>
<a href="LogoutServlet">Logout</a>
<a href="ProfileServlet">Profile</a>
</html>

login.html

<form action="LoginServlet" method="post">
Name:<input type="text" name="name"><br>
Password:<input type="password" name="password"><br>
<input type="submit" value="login">
</form>

LoginServlet.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServletextends HttpServlet{
protected void doPost(HttpServletRequestrequest, HttpServletResponseresponse)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriterout=response.getWriter();
String name=request.getParameter("name");
String password=request.getParameter("password");
if(password.equals("admin123")){
out.print("You are successfully logged in!");
out.print("<br>Welcome, "+name);
Cookie ck=new Cookie("name",name);
response.addCookie(ck);
request.getRequestDispatcher("link.html").include(request, response);
}else{
out.print("sorry, username or password error!");
request.getRequestDispatcher("login.html").include(request, response);
}
out.close();
}
}

LogoutServlet.java

import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
publicclassLogoutServletextendsHttpServlet{
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
response.setContentType("text/html");
PrintWriterout=response.getWriter();
request.getRequestDispatcher("link.html").include(request,response);
Cookieck=newCookie("name","");
ck.setMaxAge(0);
response.addCookie(ck);
out.print("youaresuccessfullyloggedout!");
}
}

ProfileServlet

public class ProfileServletextends HttpServlet{
protected void doGet(HttpServletRequestrequest, HttpServletResponseresponse)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriterout=response.getWriter();
Cookie ck[]=request.getCookies();
if(ck!=null){
String name=ck[0].getValue();
if(!name.equals("")||name!=null){
out.print("<b>Welcome to Profile</b>");
out.print("<br>Welcome, "+name);
request.getRequestDispatcher("link.html").include(request, response);
}else{
out.print("Please login first");
request.getRequestDispatcher("login.html").include(request, response);
}
out.close();
}
}

web.xml
<web-app>
<servlet>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet>
<display-name>ProfileServlet</display-name>
<servlet-name>ProfileServlet</servlet-name>
<servlet-class>ProfileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProfileServlet</servlet-name>
<url-pattern>/ProfileServlet</url-pattern>
</servlet-mapping>
<servlet>
<display-name>LogoutServlet</display-name>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>LogoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/LogoutServlet</url-pattern>
</servlet-mapping>
</web-app>

servlate

_____________html________________
<forma ction="servlet1"method="post">
Name:<inputtype="text"name="userName"/>
<br/>
<inputtype="submit"value="go"/>
</form>

_________-servlate.java_______________
importjava.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
publicclassSecondServletextendsHttpServlet{
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
{
try
{
response.setContentType("text/html");
PrintWriterout=response.getWriter();
Cookieck[]=request.getCookies();
out.print("Hello"+ck[0].getValue());
out.print("This site is under Construction");
out.close();
}
catch
(Exceptione){System.out.println(e);
}
}
}
________________-web.xml_____________

<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>

Friday 2 August 2019

Javascript | Window prompt() Method

<!DOCTYPE html>

<html>



<head>

    <title>

        Window prompt() Method

    </title>

</head>



<body style="text-align: center;">

    <h1 style="color:green;">

        GeeksforGeeks

    </h1>

    <h2>

        Window prompt() Method

    </h2>



    <button onclick="geek()">

        Click me!

    </button>

    <p id="g"></p>



    <script>

        function geek() {

            var doc = prompt("Please enter some text",

                "GeeksforGeeks");

            if (doc != null) {

                document.getElementById("g").innerHTML =

                    "Welcome to " + doc;

            }

        }

    </script>

</body>



</html> 

Enter your name on popup

 box one by one.

Alert Dialog Box

An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.
Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button "OK" to select and proceed.

Example

 Live Demo
<html>
   <head>   
      <script type = "text/javascript">
         <!--
            function Warn() {
               alert ("This is a warning message!");
               document.write ("This is a warning message!");
            }
         //-->
      </script>     
   </head>
   
   <body>
      <p>Click the following button to see the result: </p>      
      <form>
         <input type = "button" value = "Click Me" onclick = "Warn();" />
      </form>     
   </body>
</html>

Output


Confirmation Dialog Box

A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel.
If the user clicks on the OK button, the window method confirm() will return true. If the user clicks on the Cancel button, then confirm() returns false. You can use a confirmation dialog box as follows.

Example

 Live Demo
<html>
   <head>   
      <script type = "text/javascript">
         <!--
            function getConfirmation() {
               var retVal = confirm("Do you want to continue ?");
               if( retVal == true ) {
                  document.write ("User wants to continue!");
                  return true;
               } else {
                  document.write ("User does not want to continue!");
                  return false;
               }
            }
         //-->
      </script>     
   </head>
   
   <body>
      <p>Click the following button to see the result: </p>      
      <form>
         <input type = "button" value = "Click Me" onclick = "getConfirmation();" />
      </form>      
   </body>
</html>

Output


Prompt Dialog Box

The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK.
This dialog box is displayed using a method called prompt() which takes two parameters: (i) a label which you want to display in the text box and (ii) a default string to display in the text box.
This dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the window method prompt()will return the entered value from the text box. If the user clicks the Cancel button, the window method prompt() returns null.

Example

The following example shows how to use a prompt dialog box −
 Live Demo
<html>
   <head>     
      <script type = "text/javascript">
         <!--
            function getValue() {
               var retVal = prompt("Enter your name : ", "your name here");
               document.write("You have entered : " + retVal);
            }
         //-->
      </script>      
   </head>
   
   <body>
      <p>Click the following button to see the result: </p>      
      <form>
         <input type = "button" value = "Click Me" onclick = "getValue();" />
      </form>      
   </body>
</html>

Add

<!DOCTYPE html>
<html>
<head>
<title>sum of 2 number</title>
</head>
<body>
<script type=”text/JavaScript”>
var strx = prompt (“enter first number”,””);
var stry = prompt (“enter second number”,””);
var x = parseInt(strx);
var y = parseInt(stry);
var sum =x+y;
document.write(alert(sum));
</script>
</body>
</html>
:)

<script>
function GEEKFORGEEKS()                                   
{
    var name = document.forms["RegForm"]["Name"];              
    var email = document.forms["RegForm"]["EMail"];   
    var phone = document.forms["RegForm"]["Telephone"]; 
    var what =  document.forms["RegForm"]["Subject"]; 
    var password = document.forms["RegForm"]["Password"]; 
    var address = document.forms["RegForm"]["Address"]; 
   
    if (name.value == "")                                 
    {
        window.alert("Please enter your name.");
        name.focus();
        return false;
    }
   
    if (address.value == "")                              
    {
        window.alert("Please enter your address.");
        name.focus();
        return false;
    }
       
    if (email.value == "")                                  
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
   
    if (email.value.indexOf("@", 0) < 0)                
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
   
    if (email.value.indexOf(".", 0) < 0)                
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
   
    if (phone.value == "")                          
    {
        window.alert("Please enter your telephone number.");
        phone.focus();
        return false;
    }
   
    if (password.value == "")                       
    {
        window.alert("Please enter your password");
        password.focus();
        return false;
    }
   
    if (what.selectedIndex < 1)                 
    {
        alert("Please enter your course.");
        what.focus();
        return false;
    }
   
    return true;
}</script>
  
<style>
GEEKFORGEEKS {                                        
    margin-left: 70px;
    font-weight: bold ;
    float: left;
    clear: left;
    width: 100px;
    text-align: left;
    margin-right: 10px;
    font-family:sans-serif,bold, Arial, Helvetica;
    font-size:14px;
}
   
div { 
    box-sizing: border-box;
    width: 100%;
    border: 100px solid black;
    float: left;
    align-content: center;
    align-items: center;
}
   
form {                                        
    margin: 0 auto;
    width: 600px;
}</style></head>
   
<body>
<h1 style="text-align: center"> REGISTRATION FORM </h1>          
<form name="RegForm" action="/submit.php" onsubmit="return GEEKFORGEEKS()" method="post"
      
    <p>Name: <input type="text" size=65 name="Name"> </p><br>       
    <p> Address: <input type="text" size=65 name="Address">  </p><br>
    <p>E-mail Address: <input type="text" size=65 name="EMail">  </p><br>
     <p>Password: <input type="text" size=65 name="Password"> </p><br>
    <p>Telephone: <input type="text" size=65 name="Telephone"> </p><br>  
           
    <p>SELECT YOUR COURSE   
        <select type="text" value="" name="Subject">
            <option>BTECH</option>
            <option>BBA</option>
            <option>BCA</option>
            <option>B.COM</option>
            <option>GEEKFORGEEKS</option>
        </select></p><br><br>
    <p>Comments:  <textarea cols="55" name="Comment">  </textarea></p>
    <p><input type="submit" value="send" name="Submit">     
        <input type="reset" value="Reset" name="Reset">  
    </p>         
</form>
</body>
</html>