Seventh Lesson on JSP
Now we will do a small project like 1st user will register(if new candidate) and then login and after login the user can check his/her result.
Now, we will make the registration page That will be like ::
So this is our Front page "register.jsp". The code to make this page is like
<%--
Document : login
Created on : 2 Nov, 2012, 9:55:43 PM
Author : NESTED CODE
--%>
<%@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 : login
Created on : 2 Nov, 2012, 9:55:43 PM
Author : NESTED CODE
--%>
<%@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>
Now we have to make this "r1.jsp" page. The code for this page is like
Document : r1
Created on : 2 Nov, 2012, 10:37:15 PM
Author : Nested code
--%>
<%@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","system","summer3");
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>
Name of the database table is register. The code to make the table is ::
create table register(
name varchar2(20),
id varchar2(20),
password varchar2(10),
dated varchar2(10),
address varchar2(30),
primary key(id));
Now after registration the successful message will be like
Now we will check the database table(oracle is used login process is same like previous lesson)
Note: The other three row was inserted previously. The login process we will discus in the next lesson.
Check out our latest blog on Spring boot -> click here -> http://techfloat.in/search/label/springboot
Donate Us click here @ https://imjo.in/t9cEFy
sir this code shows an error at line 38 (int insertResult = ps.executeUpdate(); )of r1.jsp page..sir how can i remove this error..?
ReplyDeleteit also not inserts the values which i gave in textboxes of register.jsp page b/c of this error..
plzz sir help me out..i need this in my proj..
am using netbeans and apache server with mysql db :)
sir thanks for this code the prob or error has been solved i used try n catch in this code and now it is working good..:) :)
ReplyDeleteCan I get a code to check if user name already exists?
ReplyDeleteMailed You. Follow all instructions.
Deletei am using sql database and my database name is dilip i changed these two lines in r1.jsp
ReplyDeleteline 1:Class.forName("com.mysql.jdbc.Driver");
line 2: con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dilip","root","");
but iam getting an error at line 1
please help me out
Desired Code for this problem is ::
DeleteClass.forName("com.mysql.jdbc.Driver");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://hostname:port/dbname","username", "password");
conn.close();
Follow this instruction. Check your dbname(Database name), Password(if any) and port number once again.
If any problem, mail us directly on mailusqueries@gmail.com with exact problem and screenshot.
Thank You.
sir iam useing mysql data base for creating jsp registration form i wan to connect jsp to mysql i am useing code as
ReplyDelete<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=request.getParameter("userid");
session.putValue("userid",user);
String pwd=request.getParameter("pwd");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root","");
Statement st=con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into users values ('"+user+"','"+pwd+"','"+fname+"',
'"+lname+"','"+email+"')");
%>
but it shows an error as
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 15 in the jsp file: /reg.jsp
String literal is not properly closed by a double-quote
12: "root","");
13: Statement st=con.createStatement();
14: ResultSet rs;
15: int i=st.executeUpdate("insert into users values ('"+user+"','"+pwd+"','"+fname+"',
16: '"+lname+"','"+email+"')");
17:
18: %>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
sir plzzzzz solve my problam
please mail me the correct code and process for conecting the my sql data base to my
ReplyDeleteemail:srsrinivaslak@gmail.com
Sorry for late reply... hope you have fixed your problem.We are back with our blog with new looks. We are more organized now to provide you all a better service. Anytime let us know your query @ mailusquery@gnail.com
DeleteHowever,
Thanks for your comments! Would you like to donate us with 50/- for better service ? please click the below URL -
https://imjo.in/t9cEFy
Thanks! Keep reading our blogs! Happy Reading!
please also mail me the correct code for connecting the my sql to my database
ReplyDeleteemail:jc_gg09@yahoo.com
please also mail me the correct code for connecting the my sql to my database
ReplyDeleteemail:khomane077@.com
Sorry for late reply... hope you have fixed your problem.We are back with our blog with new looks. We are more organized now to provide you all a better service. Anytime let us know your query @ mailusquery@gnail.com
DeleteHowever,
Thanks for your comments! Would you like to donate us with 50/- for better service ? please click the below URL -
https://imjo.in/t9cEFy
Thanks! Keep reading our blogs! Happy Reading!
khomane007@gmail.com
ReplyDeleteplease use like this
ReplyDeleteint i = rs.executeUpdate();
if(i != 0)
{
out.println("insertion Successfully " + i);
and better to write String sql = "insert into emp values('"+name+"')";
//this is the better way to write code
}
if u like this please mail me althafbaig71@gmail.com
Of course we like this.. anyway we are bringing new tutorials where you may be able to wirte the same code in MVC format .. that will be more interesting and apt for these days corporate industries.
DeleteHowever,
Thanks for your comments! Would you like to donate us with 50/- for better service ? please click the below URL -
https://imjo.in/t9cEFy
Thanks! Keep reading our blogs! Happy Reading!
This comment has been removed by the author.
ReplyDeletemail me how to connect using mysql database williamotto2010@gmail.com
ReplyDeleteSorry for late reply... hope you have fixed your problem.We are back with our blog with new looks. We are more organized now to provide you all a better service. Anytime let us know your query @ mailusquery@gnail.com
DeleteHowever,
Thanks for your comments! Would you like to donate us with 50/- for better service ? please click the below URL -
https://imjo.in/t9cEFy
Thanks! Keep reading our blogs! Happy Reading!
thnq very much sir................
ReplyDeleteThanks for your comments! Would you like to donate us with 50/- for better service ? please click the below URL -
Deletehttps://imjo.in/t9cEFy
Thanks! Keep reading our blogs! Happy Reading!