aspose file tools*
The moose likes JSP and the fly likes Internal Error while Validating username and password Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Internal Error while Validating username and password" Watch "Internal Error while Validating username and password" New topic
Author

Internal Error while Validating username and password

joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
Hi Rangers

i encounter this error while trying to validate the user login name and password ,

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 22 in the jsp file: /SiteValidate.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Software Foundation\Tomcat 4.1\work\Standalone\localhost\java\SiteValidate_jsp.java:74: ';' expected
boolean isValidate(String userName, String password) {
^



An error occurred at line: 7 in the jsp file: /SiteValidate.jsp

Generated servlet error:
C:\Program Files\Apache Software Foundation\Tomcat 4.1\work\Standalone\localhost\java\SiteValidate_jsp.java:51: cannot resolve symbol
symbol : method isValidate (java.lang.String,java.lang.String)
location: class org.apache.jsp.SiteValidate_jsp
if(isValidate(userName,userPwd)) {
^
2 errors


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:248)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:343)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:427)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:142)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

and this is the code i write to get parameter form login form

index.jsp

this is the jsp validating page(SiteValidate.jsp)


please con someone help me out? am out of ideas
thanks
[ April 17, 2008: Message edited by: joseph okon ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61419
    
  67

You are trying to declare a method in the service method.
[ April 17, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

Joseph,

The error is telling you it cannot compile the jsp. First step is to check the file C:\Program Files\Apache Software Foundation\Tomcat 4.1\work\Standalone\localhost\java\SiteValidate_jsp.java, line 74.

I'm going to guess that you'll find the problem is in the line:



Looking at it alone you should see what's wrong that prevents compilation.


There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61419
    
  67

Originally posted by Stevi Deter:
I'm going to guess that you'll find the problem is in the line:
No, the JSP is invalid because he's trying to declare a method within the service method.
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
sorry guys, i don't understand??
which is the service method??
please rewrite that particular portion of code,how it's suppose to be.
thanks
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi Joseph,

You cannot define a method inside a JSP scriplet.
Try out with the following:

<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page contentType="text/html" %>
<html><body>
<%
String userName = request.getParameter("username");
String userPwd =request.getParameter("pwd");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection("jdbc:mysql:localhost:3306/filesdb","root","idoreyin");
Statement stmt s = conn.createStatement();
String sqlstat = " SELECT username FROM login" + "WHERE username =' " + userName + " ' " + "AND password =' " + password + " ' ";
ResultSet rs = s.executeQuery(sqlstat);
if(rs.next())
{
rs.close();
s.close();
conn.close();
%>
<jsp:forward page="/welcome.jsp" />
<%

}
rs.close();
s.close();
conn.close();
%>
<jsp:forward page="/invalidLogin.jsp" />
<%
}
catch(ClassNotFoundException cnfe)
{
System.out.println(cnfe.getMessage().toString());
}
catch(SQLException sqle)
{
System.out.println(sqle.getMessage().toString());
}
%>
</body>
</html>

Regards,
Kiran.
Laxmikant Ruikar
Greenhorn

Joined: Nov 29, 2005
Posts: 23
Hi Joseph

When you are declaring/writing in JSP scriplet that translated in service method while JSP to servlet translation.

If you would like to declare method then you can use JSP declarative such as

<%!
boolean isValidate(String userName, String password) {
.....
....
}
%>

Try following code


this is the jsp validating page(SiteValidate.jsp)
code:
________________________________________
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page contentType="text/html" %>

<html><body>
<%!
<%

boolean isValidate(String userName, String password) {

try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection("jdbc:mysql:localhost:3306/filesdb","root","idoreyin");
Statement stmt s = conn.createStatement();

String sqlstat = " SELECT username FROM login" + "WHERE username =' " + userName + " ' " + "AND password =' " + password + " ' ";

ResultSet rs = s.executeQuery(sqlstat);
if(rs.next()) {
rs.close();
s.close();
conn.close();
return true;
}
rs.close();
s.close();
conn.close();
} catch(ClassNotFoundException cnfe) {
System.out.println(cnfe.getMessage().toString());
} catch(SQLException sqle) {
System.out.println(sqle.getMessage().toString());
}
return false;
}
%>

<%

String userName = request.getParameter("username");
String userPwd =request.getParameter("pwd");

if(isValidate(userName,userPwd)) {
%>
<jsp:forward page="/welcome.jsp" />
<%
} else {
%>
<jsp:forward page="/invalidLogin.jsp" />
<%
}
%>
</body></html>
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
thanks guys,i have gotten solution.
i'll appreciate very much.




prefection is for God only
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
sorry for bordering you guys
my code connect to the database perfectly, but it is not validating the input from the login form rather with or without username/password,the jsp will still forward to the welcome page.
can any of you write a perfect validating code for me because i can't think any more.
thanks
i'll appreciate it


perfection is for God only
[ April 18, 2008: Message edited by: joseph okon ]
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi Joseph,

Just try out the following:

(1)Print the userid and password from the html page in the jsp page.
(2)In JSP, Instead of finding whether there is any row exist with userid and pwd, using the userid, get the password. Then compare with the password that you got from html page and the password from the query

If the above is not working out, I recommend you to keep the presentation(view) in JSP, validation in a servlet. Also keep the dbase connections in a separate class. With this design, you can easily find out where the error is instead keeping everything in a JSP.

Regards,
Kiran.
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
thanks Kumar
and the rest of the poeple for your assistant








perfection is for God only
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internal Error while Validating username and password