index.jsp:
<html>
<head>
<title>my world</title>
</head>
<body background="200491213734996.jpg">
<p>my world</p>
<form method="POST" action="manage.jsp">
  <p><input type="text" name="T1" size="20"></p>
  <p><input type="text" name="T2" size="20"></p>
  <p><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p>
</form>
</body>
</html>manage.jsp:
<%@ page import="test.Wang" %>
<head>
<title></title>
</head>
<body background="200491213734996.jpg">
<jsp:useBean id="bean" class="Wang"/>
<%
String a=request.getParameter("T1");
String b=request.getParameter("T2");
if(bean.get(a,b)){%>
<%="success!"%><%}%>Wang.java:
package test;
import java.sql.*;
public class Wang{
private String url;
private Statement stat;
private Connection con;
public Wang(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="jdbc:odbc:student";
con=DriverManager.getConnection(url,"","");
stat=con.createStatement();}
catch(SQLException e){e.printStackTrace();

catch(ClassNotFoundException e){e.printStackTrace();
}
}
public boolean get(String s,String r)throws Exception{
try{
String sql="select * from student";
ResultSet rs=stat.executeQuery(sql);
while(rs.next()){
if((rs.getString("username")).equals(s) && (rs.getString("password")).equals(r))
return true; 
} }catch(SQLException e){e.printStackTrace();
}
Exception e=new Exception();
throw e;
}
}

解决方案 »

  1.   

    我用的是tomcat,web.xml应该怎么写?
      

  2.   

    哪位高人能救我啊!!!!!
    我怀疑是web.xml的问题,或者是应用程序的配置问题。
      

  3.   

    public boolean get(String s,String r)throws Exception{
    try{
                        // ......
                      }catch(SQLException e){
                         e.printStackTrace();
    }
    Exception e=new Exception();
    throw e;
    }
    Wang类中get方法中自己抛出了异常,manage.jsp中没处理,这样可以吗?
    会不会manage.jsp中:
    String a=request.getParameter("T1");
    String b=request.getParameter("T2");
    取得的是空值。
      

  4.   

    manage.jsp中
    <jsp:useBean id="bean" class="Wang"/>
    错误,应该是<jsp:useBean id="bean" class="test.Wang"/>
    去掉<%@ page import="test.Wang" %>
      

  5.   

    恩,应该是<jsp:useBean id="bean" class=test.Wang"/>
    Wang.java放置的位置应该是对的吧?