报错:org.apache.jasper.JasperException: /WebRoot/index.jsp(26,3) The value for the useBean class attribute com.CheckLogin is invalid.
JSP:<%@ page language="java" import="java.util.*,java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="utf-8"%>
<%@ page import="com.CheckLogin"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
request.setCharacterEncoding("utf-8");
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body bgcolor="#b0e0e6">
<c:if test="${param.iflogin=='1'}">
<jsp:useBean id="checker" class="com.CheckLogin" scope="request">
<jsp:setProperty name="user" property="username" value="${param.un}" />
<jsp:setProperty name="psw" property="password" value="${param.psw}" />
<% checker.getCheck();%>
<c:if test="checker.check">
<c:set var="UserCode" value="${checker.User}" scope="session"/>
<jsp:forward page="admin.jsp" />
</c:if>
</jsp:useBean>
<center>用户名或密码错误!</center>
</c:if>
<center><br><br><br><br>
<script type="text/javascript">
//<!--
function CheckForm(form)
{
for(var i=0;i<form.elements.length;i++)
if(form.elements[i].value=="")
{
alert("请填写所有的内容!");
return false;
}
return true;
}
//-->
</script>
<form action="admin_login.jsp" method="post" onsubmit="return CheckForm(this)">
用户名:<input type="text" name="un"><br> 密 码:<input type="password" name="psw">
<input type="hidden" name="iflogin" value=1>
<br><input type="submit" value="确定"> <input type="reset" value="重写">
</form>
</center>
</body>
</html>
JAVABEAN:
package com;import java.util.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.io.*;
public class CheckLogin
{
public String user,psw;
public int wa=0;
public ResultSet rs=null;
public boolean check;
public CheckLogin()
{
}
public void setWa(int WA)
{
wa=WA;
}
public int getWa()
{
return wa;
}
public void setUser(String username)
{
user=username;
}
public String getUser()
{
return user;
}
public void setPsw(String password)
{
psw=password;
}
public String getPsw()
{
return psw;
}
public void setCheck(boolean chk)
{
check=chk;
}
public void getCheck()
{
check=false;
getConnect gC=new getConnect();
try{
wa=0;
String sql="Select * from SystemUser where UseCode='"+user+"'";
rs=gC.query(sql);
if(rs.next())
{
if(rs.getString("PassWords").equals(psw))
{
gC.closeConn();
check=true;
}
}
else
{
gC.closeConn();
check=false;
}
}
catch(Exception e)
{
gC.closeConn();
System.out.println(e.getMessage());
}
}
}
JSP:<%@ page language="java" import="java.util.*,java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="utf-8"%>
<%@ page import="com.CheckLogin"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
request.setCharacterEncoding("utf-8");
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body bgcolor="#b0e0e6">
<c:if test="${param.iflogin=='1'}">
<jsp:useBean id="checker" class="com.CheckLogin" scope="request">
<jsp:setProperty name="user" property="username" value="${param.un}" />
<jsp:setProperty name="psw" property="password" value="${param.psw}" />
<% checker.getCheck();%>
<c:if test="checker.check">
<c:set var="UserCode" value="${checker.User}" scope="session"/>
<jsp:forward page="admin.jsp" />
</c:if>
</jsp:useBean>
<center>用户名或密码错误!</center>
</c:if>
<center><br><br><br><br>
<script type="text/javascript">
//<!--
function CheckForm(form)
{
for(var i=0;i<form.elements.length;i++)
if(form.elements[i].value=="")
{
alert("请填写所有的内容!");
return false;
}
return true;
}
//-->
</script>
<form action="admin_login.jsp" method="post" onsubmit="return CheckForm(this)">
用户名:<input type="text" name="un"><br> 密 码:<input type="password" name="psw">
<input type="hidden" name="iflogin" value=1>
<br><input type="submit" value="确定"> <input type="reset" value="重写">
</form>
</center>
</body>
</html>
JAVABEAN:
package com;import java.util.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.io.*;
public class CheckLogin
{
public String user,psw;
public int wa=0;
public ResultSet rs=null;
public boolean check;
public CheckLogin()
{
}
public void setWa(int WA)
{
wa=WA;
}
public int getWa()
{
return wa;
}
public void setUser(String username)
{
user=username;
}
public String getUser()
{
return user;
}
public void setPsw(String password)
{
psw=password;
}
public String getPsw()
{
return psw;
}
public void setCheck(boolean chk)
{
check=chk;
}
public void getCheck()
{
check=false;
getConnect gC=new getConnect();
try{
wa=0;
String sql="Select * from SystemUser where UseCode='"+user+"'";
rs=gC.query(sql);
if(rs.next())
{
if(rs.getString("PassWords").equals(psw))
{
gC.closeConn();
check=true;
}
}
else
{
gC.closeConn();
check=false;
}
}
catch(Exception e)
{
gC.closeConn();
System.out.println(e.getMessage());
}
}
}
<jsp:setProperty name="user" property="username" value="${param.un}" />
<jsp:setProperty name="psw" property="password" value="${param.psw}" />
<jsp:setProperty name="user" property="username" value="${param.un}" />
<jsp:setProperty name="psw" property="password" value="${param.psw}" />
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/BOOK_DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
据说有的是因为这个有问题……
估计是在你的request 的范围内没有找到你的com.CheckLogin 这个对象。你是否在servlet或者action中设置这个对象了?
request.setAttribute() ????
<jsp:setProperty name="user" property="username" value="${param.un}" />
<jsp:setProperty name="psw" property="password" value="${param.psw}" />
JSTL标签啊 相当于声明了一个 对象
并且用<% %>是可以声明并且不报错的