提交简单表单时出错

时间:2016-07-13 11:44:01

标签: java servlets

提交简单表单时出错:

package mvc.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mvc.bean.PollBean;
import mvc.dao.PollDAO;


@WebServlet("/pollControll")

public class PollController extends HttpServlet {

    private static final long serialVersionUID = 1L;

    private PollDAO pd;

    public PollController() {

        pd = new PollDAO();
    }

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

        String action = request.getParameter("action");

        if (action.equalsIgnoreCase("SelectALL")) {

            request.setAttribute("polls", pd.SelectAll());

        }

        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

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

        String action = request.getParameter("action");

        if (action.equalsIgnoreCase(("insert"))) {


            PollDAO pp = new PollDAO();
            PollBean p = new PollBean();

        int note = Integer.parseInt(request.getParameter("note"));
        String email = request.getParameter("email");

            p.setNote(note);
            p.setEmail(email);

            pp.insert(p);

            RequestDispatcher direct = request.getRequestDispatcher("/home.jsp");

            direct.forward(request, response);

        } else if (action.equalsIgnoreCase("ResetALL")) {

            PollBean p = new PollBean();

            pd.ResetALL(p);

        } else if (action.equalsIgnoreCase("Activated")) {

            PollBean p = new PollBean();

            pd.Activated(p);

            RequestDispatcher direct = request.getRequestDispatcher("/PollAdmin.jsp");

            direct.forward(request, response);

        } else if (action.equalsIgnoreCase("Deactivated")) {

            PollBean p = new PollBean();

            pd.Deactivated(p);

            RequestDispatcher direct = request.getRequestDispatcher("/PollAdmin.jsp");

            direct.forward(request, response);
        }

        doGet(request, response);
    }

}

这里是Stacktrace:

Servlet.service() for servlet [mvc.controller.PollController] in context with path [/Enquete_eduCAPES] threw exception [Servlet execution threw an exception] with root cause
    java.lang.ClassNotFoundException: java.time.temporal.TemporalField
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:320)
        at org.postgresql.Driver.makeConnection(Driver.java:406)
        at org.postgresql.Driver.connect(Driver.java:274)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at mvc.util.ConexaoDAO.getConnection(ConexaoDAO.java:29)
        at mvc.dao.PollDAO.insert(PollDAO.java:40)
        at mvc.controller.PollController.doPost(PollController.java:60)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
        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)

1 个答案:

答案 0 :(得分:2)

您使用的是哪个版本的Java?

因为根据Java specifications版本8中引入了time/temporal/TemporalField,因此在此版本下方无效。