JSP提交验证好难啊
我用的是SQL数据库
写了一个UserMan.java的文件内容是
package kernel;
import java.sql.*;
public class UserMan{
private String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sqldata;user=sa;password=520 ";
public UserMan(){
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch (Exception ex){
ex.printStackTrace();
}
}
public boolean userExist(String userID){
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
boolean exist=true;
try{
con=DriverManager.getConnection(url);
String selectStr= "select * from userat where name=? ";
ps=con.prepareStatement(selectStr);
ps.setString(1, userID);
rs=ps.executeQuery();
if (!rs.next())
exist=false;
}
catch(SQLException exc){
exc.printStackTrace();
}
finally{
if (rs!=null) try {rs.close();} catch (SQLException ignore){}
if (ps!=null) try {ps.close();} catch (SQLException ignore){}
if (con!=null) try {con.close();} catch (SQLException ignore){}
}
return exist;
}
}
然后建了一个default.htm的文件做为登录提交的,代码是
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<form name= "form1 " method= "post " action= "login.jsp ">
<input name= "names " type= "text " id= "names ">
<input type= "submit " name= "Submit " value= "提交 ">
</form>
</body>
</html>
来了个验证login.jsp,代码是
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<jsp:useBean id= "UserMan " scope= "page " class= "kernel.UserMan "> </jsp:useBean>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<%
String username=request.getParameter( "names ");
if (!UserMan.userExist(username))
{
out.print( "error!! ");
}
else{
out.print( "ok!!! ");
}
%>
</body>
</html>
出现错误
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: kernel/UserMan (Unsupported major.minor version 49.0)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
看不明白是什么错误
[解决办法]
呵呵,应该是jdk的版本兼容问题
参考下面文章:
http://www.blogjava.net/crazycy/archive/2006/06/03/50150.html
[解决办法]
我在机器上试了没有问题,我用eclipse版本是3.1的,不支持jdk1.5
估计3.2必须用1.5以上吧
[解决办法]
原因是这样:
1.eclipse3.2默认用的是jdk1.5,我估计你没改.
2.你用的是tomcate5.0,使的jdk是j2sdk1.4.2_06,
所以错误就出来了,jdk1.4的解释不了jdk5.0编绎的类
[解决办法]
编译用高版本,用底版本运行就会出错,
反过来不会错,想下兼容
[解决办法]
这个错误其实就是 NoClassDefFoundError。楼主检查一下编译输出的位置是否正确。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html