• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP validation

 
c york
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing an application in jsp. I'm a beginner and having a problem with the validation page. I created a bean and the class is user.login. I got this code from a web site and it did not explain the class that was created completely. If there is someone who can assist, I would appreciate it.

Validate.jsp - error :user cannot resolve to a type - line 2

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<jsp:useBean id="idHandler" class="user.login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

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

************************************************
//user(class)

package user;
import java.sql.*;

public class Login {

// private String username = "";
private String password = "";

public Login() {
}
public void setPassword(String password) {
this.password = password;
}
//public void setUsername(String username) {
// this.username = username;
// }

public boolean authenticate(String username2,
String password2) {
// String query="select * from Registration;";
//String DbUserName="";
//String DbPassword="";
//String finalUser="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbcdbc:register");
Statement stat=con.createStatement();
ResultSet rst=stat.executeQuery(query);
while(rst.next())

{
// DbUserName=rst.getString("UserName");

//DbPassword=rst.getString("password");

//if (username2.equals(DbUserName) &&
//password2.equals(DbPassword)) {

break;
}


}
return true;
}catch(Exception e){

e.printStackTrace();
return false;
}
}}



public class login {

}
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

It looks like your jsp can't find login class. Are you sure it's in the classpath?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The site you got this code from must be fairly old. Doing validation like this in a JSP is very old-fashioned and frowned upon with regards to modern web application patterns. Any such processing should be done in a servlet, not a JSP.
 
Hussam Bamatraf
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<jsp:useBean id="idHandler" class="user.login" scope="request">

In the above line, the class name is not correct. It should be . [Notice the capital letter L].
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that might be the reason.

Check your FQCN (Fully Qualified Class Name) when you specify the type.

also make sure the class is visible to the container at the runtime (if its in the classpath).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic