st=conn.createStatement(); String query="select * from Users where UserName='Username'"; ResultSet rs=st.executeQuery(query); if(!rs.next()){ this.CheckMessage=("the user is not exist"); } while(rs.next()){ this.Userpasswordget=rs.getString("UserPassword"); } st.close(); conn.close(); } catch(Exception em){ System.out.println(em); } return this.Userpasswordget; } public String getCheckMessage(){ if(this.Userpasswordget==this.Userpasswordset){ this.CheckMessage=("successed"); } else this.CheckMessage=("wrong password");
return this.CheckMessage; } }出错信息为:type Status reportmessage /login_conform.jspdescription The requested resource (/login_conform.jsp) is not available.
在java中用jdbc连接数据库的写法基本都相同,只是各种数据库的driver不同而已。
无非都是先注册数据库驱动程序:class.forName(数据库的驱动driver); 然后用DriverManager.getConnection(数据库url,用户名,密码);获得连接。
至于你的javabean用什么写出来的都一样,java程序放到那也无所谓,关键是编译后的class文件的位置,可以放到tomcat默认得root/WEB-INF/class下,也可以放到其他目录,如果放到其他目录的话,在tomcat的conf目录下的server.xml文件配置一下,指明你的系统运行目录就ok了。
以后有问题希望大家还能够多指教!
html代码:
<html>
<head>
<title>User Confirm</title>
</head>
<body>
<center>
<%@ page language="java"%>
<jsp:usebean id="Test1" scope="application" class="Test1"/><jsp:setProperty name="Test1" property="Username" value="aniu">
<jsp:setProperty name="Test1" property="Userpasswordset" value="810131">
<jsp:getProperty name="Test1" property="Userpasswordget">
<br>
Return Message:<jsp:getProperty name="Test1" property="CheckMessage"></body>
</html>bean代码:import java.sql.*;
public class Test1{
String Userid;
String Username;
String Userpasswordset;
String Userpasswordget;
String CheckMessage;
public Test1(){
}
public void setUsername(String username){
this.Username=username;
}
public void setUserpassword(String userpassword){
this.Userpasswordset=userpassword;
}
public String getUserpassword(){
Statement st;
Connection conn;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:studyweb","system","admin");
st=conn.createStatement();
String query="select * from Users where UserName='Username'"; ResultSet rs=st.executeQuery(query);
if(!rs.next()){
this.CheckMessage=("the user is not exist");
}
while(rs.next()){
this.Userpasswordget=rs.getString("UserPassword");
}
st.close();
conn.close();
}
catch(Exception em){
System.out.println(em);
}
return this.Userpasswordget;
}
public String getCheckMessage(){
if(this.Userpasswordget==this.Userpasswordset){
this.CheckMessage=("successed");
}
else this.CheckMessage=("wrong password");
return this.CheckMessage;
}
}出错信息为:type Status reportmessage /login_conform.jspdescription The requested resource (/login_conform.jsp) is not available.
这个文件的路径有错。检查一下。
在jsp页中调用bean中的getUserpasswordget方法时,页面发生错误。提示为:无法为jsp编译改(Test1)类!
何解?????
如果将getUserpasswordget方法里面的数据库链接给屏蔽掉,页面就可以运行,但返回的只能是NULL。
何解?????
还有一个得和大家澄清一下,我的getUserpasswordget()和setUserpasswordset()改为getUserpassword()和setUserpassword()才可以运行,不知道是不是java不支持这么长的方法名。一开始的错误就出现在这里。