Pages

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>


No comments:

Post a Comment