• 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

authentication problem

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all

i m trying to make a simple authentication program.in which i take username and password from one jasp and maching in another jsp. code is here

%@ page language="java" %>
<%@ page import="java.util.*" %>

<%

Static check = no;
String username = request.getParameter("username");
String password = request.getParameter("password");



public void authenticate( String username,String password) {

String query="select * from Registration;";
String DbUserName="";
String DbPassword="";
String finalUser="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:Registration");
Statement stat=con.createStatement();
ResultSet rst=stat.executeQuery(query);
while(rst.next())

{
DbUserName=rst.getString("UserName");
DbPassword=rst.getString("password");

if (username.equals(DbUserName) && password.equals(DbPassword)) {

check = yes;
break;
}

}

}catch(Exception e){

e.printStackTrace();

}
if (check==yes) {
%>
<jsp:forward page="success.jsp"/>
<%
} else {
%>
<jsp:forward page="retry.jsp"/>
<%
}

}
%>
__________________________

when i m compile this its giving error like this:

An error occurred at line: 5 in the jsp file: /jsp/process2.jsp
Generated servlet error:
Syntax error on token "(", ; expected

An error occurred at line: 5 in the jsp file: /jsp/process2.jsp
Generated servlet error:
Syntax error on token ",", ; expected

An error occurred at line: 5 in the jsp file: /jsp/process2.jsp
Generated servlet error:
Syntax error on token ")", ; expected



plz help me or give me another piece of code .....

thanks in advance

vinay
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Vinay.

Could you tell if the JSP that you have given here, is it named as process2.jsp. Or is it the forward page.
 
vinaykumar singh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Vasudevan Badri

it is process2.jsp and if the user is authenticated then success.jsp is forwarded otherwise retry.jsp.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vinay,

You cant write Java functions (methods) within the the <% %>. The code in in JSP will be generated inside the _jspService method. So that is the reason you get the compilation errors.

To put java function inside generated JSP class file you need to put in the <%! %> . This will make the code to be generated inside the JSP class file. Beware JSP instances are singleton, so if you declare any variable inside the <%! %> (class scope), it will be shared across all the requests from all the users.

You can use the session object to store the values pertaining to a particular user.

Hope this helps.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Caution: Do care of thread safety. Otherwise, it can show you hell.
reply
    Bookmark Topic Watch Topic
  • New Topic