My brother Ravi Tamada request one mail about his college presentation. He is planning to do web dynamic project. So i am giving small explanation about JSP (Java Server Pages) to Mysql Connection structure, Tomcat directory structure and simple database examples.
Login.html
Code :
<body>
<form action="login.jsp" method="post">
User name :<input type="text" name="usr" />
password :<input type="password" name="pwd" />
<input type="submit" />
<form action="login.jsp" method="post">
User name :<input type="text" name="usr" />
password :<input type="password" name="pwd" />
<input type="submit" />
</form>
</body>Reg.html
code:
<form action="reg.jsp" method="post">
Email :<input type="text" name="email" />
First name :<input type="text" name="fname" />
Last name :<input type="text" name="lname" />
User name :<input type="text" name="userid" />
password :<input type="password" name="pwd" />
<input type="submit" />
</form>
Mysql Create Database Test:
Mysql no doubt about it best open source database http://mysql.com/
Create Table Users:
login.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String userid=request.getParameter("user");
session.putValue("userid",userid);
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/
test","root","root");
Statement st= con.createStatement();
ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
if(rs.next())
{
if(rs.getString(2).equals(pwd))
{
out.println("welcome"+userid);
}
else
{
out.println("Invalid password try again");
}
}
else
%>
reg.jsp
<%@ 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","root");
Statement st= con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into users values ('"+user+"','"+pwd+"','"+fname+"',
'"+lname+"','"+email+"')");
%>
welcome.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=session.getValue("userid").toString();
%>
Registration is Successfull. Welcome to <%=user %>
Tomcat Directory Structure
Tomcat open source web server you can download from this link http://tomcat.apache.org/
Run Your Project
wat about the login.html and reg.html for these........sri?
ReplyDeletei want to have those yaar............
ReplyDeleteplzz post those first sri......
.how to connect these jsp to html pages.........
ReplyDeletehie srinivas,........plz explain how jsp and html pages get connected........plz post yaar.....!!
ReplyDeletelogin.html and reg.html Code posted......
ReplyDeleteSimply stated, JDBC makes it possible to write platform independent Java programs that can be used to manipulate the data in a wide range of SQL databases without the requirement to modify and/or recompile the Java programs when moving from platform to platform or from DBMS to DBMS. MySQL is available for a wide variety of platforms.
ReplyDeleteits a nice post
ReplyDeletevery good this post. thanks
ReplyDeletesrinivas ur post was excellent..can you help me out with this..this user login when submit must go to another page that displays another html form.
ReplyDelete@Harini
ReplyDeletelogin.jsp include redirect .html
request.getRequestDispatcher("/xyz.html");
Where is Download button :)
ReplyDeleteThanks this Connecting JSP To Mysql Database Lesson very useful to me!!!!!!
ReplyDeleteHi Srinivas, I refer ur example for my application but i face on problem means getting an error so plz help me.
ReplyDeleteThe exception is follow:
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
plz plz help me
Regards,
Mahesh
hi sir,
ReplyDeletehow to run this project in glassfish server.
i got the error as resources not available can u explan it clearly pls
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Login' did not find a matching property.
ReplyDeleteorg.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
.apache.catalina.startup.Catalina load
INFO: Initialization processed in 355 ms
Mar 13, 2012 11:48:26 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 13, 2012 11:48:26 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
Mar 13, 2012 11:48:26 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 13, 2012 11:48:26 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 13, 2012 11:48:26 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 207 ms
Mar 13, 2012 11:48:34 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Login] threw exception [An exception occurred processing JSP page /login.jsp at line 8
5: String userid=request.getParameter("user");
6: session.putValue("userid",userid);
7: String pwd=request.getParameter("pwd");
8: Class.forName("com.mysql.jdbc.Driver");
9: java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","dba");
10: Statement st= con.createStatement();
11: ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
Stacktrace:] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.servicee)
I m Facing this error anyone say me solutions...
hi, i highly appreciate the way you explain this connection but can you please explain how i can add date field and checkbox to my database and link it to a jsp page, the same way you explain the login process.
ReplyDeletethanks
Thank you very much!
ReplyDeleteI have a problem in the code in line of connection
ReplyDeleteDriverManager.getConnection("jdbc:mysql://localhost:3306..
tell me the problem srinivas..
my problem also not connected data base sir plz replay
DeleteChange the local host ID I.e; in the eg it is 3306.
DeleteKindly change it to your local host ID which will be by default 8080
To people getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver you should download the jdbc mysql jar and add it to lib folder on your tomcat server.
ReplyDeletePrashant Tyagi should see if his database is on and on port 3306. Mysql default port is 3386..
Glad to be of assistance. :)
org.apache.jasper.JasperException: Unable to compile class for JSP:
ReplyDeleteAn error occurred at line: 25 in the jsp file: /reg.jsp
String literal is not properly closed by a double-quote
22: java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3386/test1");
23: Statement st=con.createStatement();
24: ResultSet rs;
25: int i=st.executeUpdate("insert into user values ('"+user+"','"+pwd+"','"+fname+"',
26: '"+lname+"','"+email+"')");
27:
28:
Can you solve my problem? after clicking submit button I get this:
ReplyDelete" SEVERE: PWC6117: File "C:\...\build\web\login.jsp" not found "
login.jsp is in the same folder with login.html
Create a Table in Mysql database through SQL Query in JSP,this Connecting JSP To Mysql Database Lesson very useful, I need a program to provide download option for pdf file on my web page,the pdf file contains retrieved data from mysql table. I need this program by using jsp-servlets. any one can help me please
ReplyDeleteexcellent
ReplyDeletenice code thanks
ReplyDeleteMy code does't work ,, hiks
ReplyDeletewjhen i click on the submit button it goes to the login.jsp but it displays a blank page.
ReplyDeleteand yes i have used setAttribute instead of getValue
DUDE
ReplyDeleteI DID A MISTAKE IN CODING
In Login.html
name="usr"
login.jsp
request.getParameter("user")
usr & user?
nice presentation.......
ReplyDeleteHey srinivas ,
ReplyDeletehow to assign a session variable to a normal variable,n print ??
And String user=session.getValue("userid").toString(); tis code not wrkin....
thanks a lot very nicely explained
ReplyDeletehi..Nice explanation.but how can i use both insert and retrive query in same jsp file ..Plz help me..im new to JSP
ReplyDelete
ReplyDeleteI GOT THIS ERROR..MAY I HAVE SOLUTION FOR THIS....
org.apache.jasper.JasperException: An exception occurred processing JSP page /Register.jsp at line 12
9: String userid=request.getParameter("user");
10: session.putValue("user_id",userid);
11: String pwd=request.getParameter("pwd");
12: Class.forName("com.mysql.jdbc.Driver");
13: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3386/tests","root","deepti");
14: Statement st= con.createStatement();
15: ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
@Deepti
ReplyDeleteCopy servlet.jar file into lib folder
Hello srinivas,
ReplyDeleteI have added servlet.jar file into lib folder.. but again , same problem is here...
and
session.putValue("user_id",userid);
i got a warning in this line...
I need to diplay login.jsp in login.html page only by clicking button please help me.
ReplyDeletehelped me lot 2 understand some basics
ReplyDeletereally helpful
ReplyDeleteits nice working for me
ReplyDeleteSimple and easy way to understand...thanks I got what I wanted... excellent..!
ReplyDeletetype Exception report
ReplyDeletemessage
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
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","tiger");
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:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
what is the error???
The server encountered an internal error () that prevented it from fulfilling this request.
ReplyDeleteexception
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","tiger");
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:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
how to solve it
We compiled login.jsp and we have got the following errors. Kindly help me out.
ReplyDeletecompile-single-jsp:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
Created dir: C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src
Created dir: C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\classes
Compiling 1 source file to C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\classes
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:74: illegal start of expression
} catch (Throwable t) {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:74: 'catch' without 'try'
} catch (Throwable t) {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:74: ')' expected
} catch (Throwable t) {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:74: not a statement
} catch (Throwable t) {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:74: ';' expected
} catch (Throwable t) {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:81: 'finally' without 'try'
} finally {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:35: 'try' without 'catch' or 'finally'
try {
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\build\generated\src\org\apache\jsp\login_jsp.java:85: reached end of file while parsing
}
8 errors
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\nbproject\build-impl.xml:597: The following error occurred while executing this line:
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\nbproject\build-impl.xml:589: The following error occurred while executing this line:
C:\Users\Administrator\Documents\NetBeansProjects\LoginTest\nbproject\build-impl.xml:285: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 11 seconds)
i want to crate login page and connnect badabase match username and password then open wellcome page in jsp. using jsp & servlet
ReplyDelete:D
ReplyDeleteGot a error like this
ReplyDeleteorg.apache.jasper.JasperException: An exception occurred processing JSP page /verifyreg.jsp at line 28
25: String state=request.getParameter("cstate");
26: String coun=request.getParameter("country");
27:
28: Class.forName("com.mysql.jdbc.Driver");
29: java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
30: Statement st= con.createStatement();
31: ResultSet rs;
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.verifyreg_jsp._jspService(verifyreg_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:186)
org.apache.jsp.verifyreg_jsp._jspService(verifyreg_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.
thanks for the tutorial. i don't understand how it selects the database "test"
ReplyDeleteThank u soo much srinivas it works for me...
ReplyDeleteBut in login.jsp code :
out.println(...) not working..
btw all its awesome! Thanks a Lot
I find this is great intro to JSP login with Mysql and Tomcat, I worked out the blank login.jsp page as Pankaj wrote earlier there.
ReplyDeleteWhat to do once register is done though, wouldn't it be useful to send back to the login page?
Also I wonder about the Welcome.jsp use as it's not linked to any of the other files..
I want to implement functions to allow user to input data in other tables so I need to know who is logged in to identify those inputs.
How can 'log out' function be implemented to complete the system?
Thanks for your input
good
ReplyDeletejava.lang.ClassNotFoundException: com.mysql.jdbc.Driver
ReplyDeletegetting this error ...
yeah..but when we do this in servlet..we use to do it in try/catch...this may help us to avoid exception
DeleteThank you it was of really great help
ReplyDeletekudos
NB if you have done everything and your site is giving sql errors please uplaod the mysql jar file in the libraries
very excellent site i never seen that . for me need
ReplyDeleteaccurately available in this site thank u anna by anand salem tamilnadu
Hi, This conntent is Realy good and well structured including the images. my name is JC from venezuela, im a Network Enginer and im starting in web app´s. My congratulations.
ReplyDeleteplz help me once i click on the login button
ReplyDeletethe the code of login.jsp is displayed and the file doesnt runs
Those who who had the issues with the ..
ReplyDelete"java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
errors and so on..
YOu need to place the "mysql-jdbc.jar" file to the "/WEB-INF/lib" directory.
restart tyour app server and try again..
Also there is a typo error in login.html ..repalce "usr" with "user" ..
Thanks man. tht was really helpful.
ReplyDeletehow you create above diagrams? using any software tool .....plz tell i want use in my paper persentaion PPT...
ReplyDeletekudos !! nice tutorial here...
ReplyDeletethnxx
I GOT THIS ERROR:
ReplyDeleteorg.apache.jasper.JasperException: An exception occurred processing JSP page /project/insert.jsp at line 18
15: user="root" password=""/>
16:
17:
18:
19: INSERT INTO Booking VALUES ('<%= request.getParameter("CompanyName") %>','<%= request.getParameter("BikeName")%>','<%= request.getParameter("CustomerName") %>','<%= request.getParameter("CustomerAddress") %>','
20:
21:
hello sir i am using mqsql 5.1 version . you dont tell how to connect with jsp to database. you tell to me connection procedure sir please.
ReplyDeletehi i am ashok how to connect to jsp servlet and javabean
ReplyDeleteHi I am shivshankar,
ReplyDeleteThank you for this tutorial but i got an error like following
type Exception report
message javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 's' in 'field list'
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 's' in 'field list'
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 's' in 'field list'
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.reg_jsp._jspService(reg_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 's' in 'field list'
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
com.mysql.jdbc.Connection.execSQL(Connection.java:3118)
com.mysql.jdbc.Statement.executeUpdate(Statement.java:1313)
com.mysql.jdbc.Statement.executeUpdate(Statement.java:1232)
org.apache.jsp.reg_jsp._jspService(reg_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.
thank you sir for giving this information.........
ReplyDeleteSimple and effective!
ReplyDeletewhat is username and pasword????
ReplyDeleteorg.apache.jasper.JasperException: Unable to compile class for JSP:
ReplyDeleteAn error occurred at line: 23 in the jsp file: /login.jsp
Syntax error on token "else", EmptyStatement expected after this token
20: out.println("Invalid password try again");
21: }
22: }
23: else
24: %>
HOW TO SOLVE THIS ERROR????
Hello Srinivas,
ReplyDeleteI am big fan of your tutorial. I have started to learn JSP+Servlet. I am having problem to insert auto increment primary key. see my below code in two different format.
Code-1
-----------
Class.forName(JDBC_DRIVER);
// Open a connection
out.println("Connecting to a selected database...");
con = DriverManager.getConnection(DB_URL, USER, PASSWORD);
out.println("Connected database successfully...");
// Execute a query
st = con.createStatement();
sql = "insert into users (name,email,password) values ('" + name + "','" + email + "','" + password + "')";
out.println(sql);
int i = st.executeUpdate(sql);
if (i > 0) {
out.println("Inserted!!");
}
Code-2
-----------
Class.forName(JDBC_DRIVER);
con = DriverManager.getConnection(DB_URL, USER, PASSWORD);
PreparedStatement ps;
st = con.createStatement();
sql = "insert into users (name,email,password) values (?,?,?)";
ps = con.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
ps.setString(1, name);
ps.setString(2, email);
ps.setString(3, password);
ps.executeUpdate();
keep files like this.
ReplyDeleteprogram files->
Apache tomcat software foundation->
Tomcat7.0->
webapps->create new folder(like test)
keep files(.jsp and .html) in this folder->
WEB-INF->
.xml(web.xml)
lib->.jar file(mysql-connector-java-5.1.18-bin)
could any one resolve my problem in the above program.....
ReplyDeletetype Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.class1.login_jsp._jspService(login_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:190)
org.apache.jsp.class1.login_jsp._jspService(login_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.22 logs.
Apache Tomcat/7.0.22
plz post some other projects also like students' database for a collage
ReplyDeletei cant able to connect database with jsp page .The fields which we enter are not getting connected to database so could u plz help me...
ReplyDeletethanks
ReplyDeleteHi
ReplyDeleteAnyone who can help with this error, I would appreciate.
org.apache.jasper.JasperException: An exception occurred processing JSP page /test/reg.jsp at line 10
7: String fname=request.getParameter("fname");
8: String lname=request.getParameter("lname");
9: String email=request.getParameter("email");
10: Class.forName("com.mysql.jdbc.Driver").newInstance();
11: java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users",
12: "root","lehlo");
13: Statement st= con.createStatement();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
thank for the post. :) Good post.
ReplyDeleteis very useful and can be understood
where can i run this program
ReplyDeleteworking fine. After registration page is not diverting to welcome.jsp . data is inserted successfully
ReplyDeleteand. login.jsp is working fine
your code executed successfully. I put the welcome.jsp code "Registration is Successfull. Welcome to <%=user %>" below reg.jsp to get the desired result
ReplyDeleteHTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
ReplyDeletetype Exception report
message The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:56)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:445)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:117)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:325)
org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:154)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1410)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs.
thanks
ReplyDeleteweb.xml file are not there
ReplyDeleteit is not madatory to use web.xml .we can approach by using tightly coupled technique..
Deletemy problem is .jsp page not found and at com.dell.LoginServlet.doGet(LoginServlet.java:26)
ReplyDeletesolve this problem
Working. Thanks for the post. Lot may get helped.
ReplyDeleteorg.apache.jasper.JasperException: Unable to compile class for JSP:
ReplyDeleteAn error occurred at line: 8 in the jsp file: /jsp/sample1.jsp
String literal is not properly closed by a double-quote
5: session.putValue("user_id",userid);
6: String pwd=request.getParameter("pwd");
7: Class.forName("com.mysql.jdbc.Driver");
8: java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/
9: login","root","root");
10: Statement st= con.createStatement();
11: ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:490)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.73 logs.
pplz hlp
<%@page import="java.text.DateFormat"%>
ReplyDelete<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import= "java.sql.*" %>
<%@page import="java.io.*" %>
<%
try
{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/amit","root","root");
String sql="select *from students";
PreparedStatement ps=cn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
out.println(rs.getString("rollno"));
out.println(rs.getString("name"));
out.println(rs.getString("course"));
out.println();
}
}
catch(Exception ex)
{
out.println(ex.getMessage());
}
%>
Awesome, very helpful worked like a charm. Thanks for sharing
ReplyDeleteVery good description.
ReplyDeleteBut how can we link two pages I.e; after submitting the login/registration page it should be redirected to welcome page .
How can we link them.
Kindly requesting to solve my issue.
Regards,
Vineeth Raj.
how does request.getRequestDispatcher works?? I have included in the jsp file, but it doesnt work ??????
ReplyDeletehow does request.getRequestDispatcher works????? i have included in the jsp file, but it doesnt go from login page to reg page
ReplyDeletei think you can try in this way
ReplyDeleteRequestDispatcher rs = request.getRequestDispatcher("login.html");
rs.forward(request, response);
dont cleared how submit button works?
ReplyDeletehello, whenever i fill the employee id i want the other details to be autofilled from the database.. help plz
ReplyDelete