Tomcat服务器HTTP状态500?内部服务器错误

时间:2018-03-31 20:02:22

标签: java tomcat mysql-workbench

代码

@WebServlet("/TestMySqlServlet")
public class TestMySqlServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

@Resource(name="jdbc/test")
private DataSource dataSource;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    PrintWriter out = response.getWriter();
    response.setContentType("text/plain");

    Connection con;
    Statement stmt;

        try {

            con = dataSource.getConnection();

            String uname;
            String uclass;

            uname = request.getParameter("name");
            uclass = request.getParameter("class");

            String query = "insert into info Values('"+uname+"','"+uclass+"')";

            stmt = con.createStatement();

            boolean flag = stmt.execute(query);

            if(flag) {
                out.write("<h3>Data Inserted Successfully</h3>");
            }else {
                out.write("<h3>Data Insertion Failed</h3>");
            }

        } catch (SQLException e) {
            out.print("Connection Error");
            e.printStackTrace();
        }   
    }
}

上下文

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Context>
<Resource name="jdbc/test" 
        auth="Container" 
        type="javax.sql.DataSource"
        maxActive="20"
        maxIdle="5"
        maxWait="10000"
        username="hamza" 
        password="qwerty" 
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/test?useSSL=false"/>
</Context>

异常堆栈跟踪

SEVERE: Servlet.service() for servlet [main.TestMySqlServlet] in context with path [/TestMySql] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.aspectj.lang.Signature
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2154)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2061)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1543)
at main.TestMySqlServlet.doPost(TestMySqlServlet.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

当我运行我的代码时,它显示错误HTTP状态500?内部服务器错误。有什么问题?我怎么能解决这个问题?我还在WEB-INF / lib目录中添加了mysql-connector-java-5.1.38-bin.jar文件。我使用MySQL Workbench作为数据库。在打印控制台中,它表示SEVERE:Servlet.service()for servlet [main.TestMySqlServlet] in 上下文与路径[/ TestMySql]抛出异常[Servlet执行 根本原因引发了一个例外

0 个答案:

没有答案