File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Login jsp page error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Login jsp page error" Watch "Login jsp page error" New topic
Author

Login jsp page error

ratnala jagadeesh
Greenhorn

Joined: Aug 03, 2012
Posts: 3
authentication.jsp
---------------------


<%@ page import="java.sql.*"%>
<%! Connection con;
PreparedStatement ps;
public void jspInit()
{
ServletConfig config=getServletConfig();
String dr=config.getInitParameter("driver");
String cs=config.getInitParameter("dburl");
String usr=config.getInitParameter("username");
String pwd=config.getInitParameter("password");
try
{
Class.forName(dr);
con=DriverManager.getConnection(cs,usr,pwd);
ps=con.prepareStatement("select * from registration where username=? and password=?");
}
catch(Exception e)
{
}
}
public void jspDestroy()
{
try
{
ps.close();
con.close();
}
catch(Exception e)
{
}
}
%>

<%
String user=request.getParameter("username");
String pwd=request.getParameter("password");
ps.setString(1,user);
ps.setString(2,pwd);
ResultSet rs=ps.executeQuery();
boolean b=rs.next();
rs.close();
%>

<html>
<body bgcolor=cyan>
<%
if(b)
{
%>

<h1> welcome to your profile</h1>

<%
}
else
{
%>
<h1>login failed invalid username or password </h1>
<A HREF=login.html>try again</A>
<%
}
%>
</body>
</html>






login.html
------------


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Login </title>
</head>
<body bgcolor="skyblue">
<center><H1> Login Page</H1>
<form method="POST" Action="authentication.jsp">
username<input type="text" name="username"><br><br>
password<input type="password" name="password"><br><br>

<input type ="submit" value="login">
</form>
</center>

</body>
</html>


web.xml
-------------


<web-app>
<servlet>
<servlet-name>one</servlet-name>
<jsp-file>/authentication.jsp</jsp-file>

<init-param>
<param-name>driver</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
</init-param>

<init-param>
<param-name>dburl</param-name>
<param-value>jdbc:oracle:thin:@localhost:1521:XE</param-value>
</init-param>

<init-param>
<param-name>username</param-name>
<param-value>system</param-value>
</init-param>

<init-param>
<param-name>password</param-name>
<param-value>1234</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>one</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>







i had saved all the files in loginjspapplication2 folder,
i have entered the url

http://localhost:8081/loginjspapplication2/

when i press this i get the error



exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /authentication.jsp at line 37

34: <%
35: String user=request.getParameter("username");
36: String pwd=request.getParameter("password");
37: ps.setString(1,user);
38: ps.setString(2,pwd);
39: ResultSet rs=ps.executeQuery();
40: boolean b=rs.next();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)



Can anyone help please.....

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

First step: move all the Java code out of the JSPs. Please read this JspFaq entry.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ratnala jagadeesh
Greenhorn

Joined: Aug 03, 2012
Posts: 3
[quote=Bear Bibeault]First step: move all the Java code out of the JSPs. Please read [url=http://www.coderanch.com/how-to/java/WhyNotUseScriptlets]this JspFaq entry[/url].[/quote]


sir as i am a basic learner towards jsp, i did not get you what you had said. but i rectified the error somewhat by keeping

Class.forName("oracle.jdbc.driver.OracleDriver");
String cs1="jdbc:oracle:thin:@localhost:1521:XE";
con=DriverManager.getConnection(cs1,"system","1234");

in place of

Class.forName(dr);
con=DriverManager.getConnection(cs,usr,pwd);

in authentication.jsp
ratnala jagadeesh
Greenhorn

Joined: Aug 03, 2012
Posts: 3
[quote=ratnala jagadeesh][quote=Bear Bibeault]First step: move all the Java code out of the JSPs. Please read [url=http://www.coderanch.com/how-to/java/WhyNotUseScriptlets]this JspFaq entry[/url].[/quote]


sir as i am a basic learner towards jsp, i did not get you what you had said. but i rectified the error somewhat by keeping

Class.forName("oracle.jdbc.driver.OracleDriver");
String cs1="jdbc:oracle:thin:@localhost:1521:XE";
con=DriverManager.getConnection(cs1,"system","1234");

in place of

Class.forName(dr);
con=DriverManager.getConnection(cs,usr,pwd);

in authentication.jsp[/quote]









But really that is not the solution i think some problem is there with web.xml as i amtrying to rectify can you please help me...
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

@ Ratnala - Bear said that use the java codes in servlet not in jsp. This is because of performance as if you use more java codes in jsp will lead to reduce performance... Use the code tag given in the form put your doubt or error codes inside the code tags so that readers can easily read and give you the solution. hope you understand it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Login jsp page error