| Author |
authentication problem
|
vinaykumar singh
Greenhorn
Joined: Jan 14, 2006
Posts: 13
|
|
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
|
 |
Vasudevan Badri
Greenhorn
Joined: Mar 20, 2006
Posts: 6
|
|
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
Joined: Jan 14, 2006
Posts: 13
|
|
hello Vasudevan Badri it is process2.jsp and if the user is authenticated then success.jsp is forwarded otherwise retry.jsp.
|
 |
Manesh Kumar
Ranch Hand
Joined: Mar 21, 2006
Posts: 94
|
|
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.
|
Manesh
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
|
Caution: Do care of thread safety. Otherwise, it can show you hell.
|
 |
 |
|
|
subject: authentication problem
|
|
|