新手求教JSP怎么使用javabean
我有个B.JSP文件接受A.JSP文件传递来的值,想用javabean判断是否和数据库里有重复,java文件已经试过没问题(我具体在JAVA文件里赋值测试没问题)。但是在JSP里无论接受什么值都说已经重复。怎么办?
JSP:
<%String username= "1223 ";%> //假设1223是传递来的值
<jsp:useBean id= "ID " class= "count.Username " scope= "page "/>
<%String end = ID.namecheck();%>
<%=end%>
JAVA:
public String namecheck(){
Connection conn = null;
Statement stmt=null;
ResultSet rs = null;
String username=null;
String end = "you can use the username! ";
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
conn = DriverManager.getConnection( "jdbc:odbc:register ");
stmt = conn.createStatement();
String sql = "select * from register where username= ' "+username+ " ' ";
rs = stmt.executeQuery(sql);
while(rs.next()){
String username2 = rs.getString( "username ");
if(username==username2 || username2.equals(username)){
end = "username is being! ";
}
}