jsp:useBean找不到类,为什么呢?
The value for the useBean class attribute login.loginbean is invalid.
在网上搜了好多帖子也不能解决,苦恼
eclipse里的tomcat项目,目录如下:
项目名
|--web
|--login
|--logincheck.jsp
|--index.jsp
|--WEB-INF
|--classes
|--login
|--loginbean.class
|--lib
|--src
|--login
|--loginbean.java
|--work
下面贴代码:
logincheck.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"
errorPage="" %>
<%@ page import="login.*" %>
<jsp:useBean id="userbean" class="login.loginbean" scope="page">
<jsp:setProperty name="userbean" property="*"/>
</jsp:useBean>
<%
if (user.checklogin())
{
String username = request.getParameter("username");
session.setAttribute("username", username);
%>
<jsp:forward page="success.jsp"/>
<%
}
else
{
%>
<jsp:forward page="failure.jsp"/>
<%
}
%>
loginbean.java
package login;
import java.sql.*;
public class loginbean
{
private String username;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public loginbean(){
username="";
password="";
}
public boolean checklogin()
{
boolean loginflag = false;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://10.54.0.134:1433;DatabaseName=sshtest","sa","oa");
stmt = con.createStatement();
String sql ="select * from tbluser where loginid='"+username+"' and passwd='"+password+"'";
rs = stmt.executeQuery(sql);
while (rs.next())
{
if(password.equals(rs.getString("passwd")))
{
loginflag=true;
}
}
}
catch (Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null)
{
try
{
con.close();
}
catch (
SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
}
return loginflag;
}
}
------解决方案--------------------
你把logincheck.jsp放在和WEB-INF同级目录下试一下.
------解决方案--------------------
那样写javabean是没有问题的,我觉得19楼说的是正解。为避免jsp文件都放到根目录下,可以在WEB-INF下建立个目录,全部放那里面啊~~只是在转页面的时候要注意点添加目录而已
------解决方案--------------------
|--WEB-INF
|--classes
|--login
|--loginbean.class
|--lib
|--src