• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Internal Error while Validating username and password

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are trying to declare a method in the service method.
[ April 17, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys,i have gotten solution.
i'll appreciate very much.




prefection is for God only
 
joseph okon
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Kumar
and the rest of the poeple for your assistant








perfection is for God only
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic