package com.suda;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.sql.*;
class yanZheng extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
Connection cn = null;
Statement sm = null;
ResultSet rs = null;
try {
String u = req.getParameter(“username”);
String p = req.getParameter(“userpassword”);
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
cn = DriverManager
.getConnection(
“jdbc:sqlserver://localhost:1433; DatabaseName=user”);
sm = cn.createStatement();
rs = sm.executeQuery(“select * from userTable where name=”””
+ u + “””and password =””” + p + “”””);
if (rs.next()) {
HttpSession hs = req.getSession(true);
hs.setMaxInactiveInterval(10);
hs.setAttribute(“name”, u);
resp.sendRedirect(“Success”);
} else {
resp.sendRedirect(“Login”);
}
} catch (Exception ex) {
ex.printStackTrace();
}
/*finally {
try {
if (cn != null) {
cn.close();
}
if (sm != null) {
sm.close();
}
if (rs != null) {
rs.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}*/
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
异常是:
严重: Allocate exception for servlet yanZheng
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class com.suda.yanZheng with modifiers “”
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)
at java.lang.Class.newInstance(Class.java:427)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
编译没有错 3个jar包也导入了eclipse 为啥出现这个错误 数据库名也对的