0
public class AddMovieServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public AddMovieServlet() {
    super();
    // TODO Auto-generated constructor stub
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    super.doPost(req, resp);

    process(req,resp);
}


@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    super.doGet(req, resp);
    process(req,resp);
}


//my process method
protected void process(HttpServletRequest req , HttpServletResponse resp)
{
    //we will set up requests of the elements of our movie

    String name = req.getParameter("name");
    long date = Long.parseLong(req.getParameter("relDate").toString());
    String lang = req.getParameter("lang");
    int rating = Integer.parseInt(req.getParameter("rating"));
    String descr = req.getParameter("descr");

    String DBURL = "jdbc:mysql://localhost:8080/moviedb";
    String query = "INSERT INTO movieTable VALUES (?,?,?,?,?)";

    Connection myConnection = null;
    PreparedStatement myStatement = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        myConnection = DriverManager.getConnection(DBURL,"root","root");
        myStatement = myConnection.prepareStatement(query);
        myStatement.setString(1, name);
        myStatement.setLong(2, (int)date);
        myStatement.setString(3, lang);
        myStatement.setInt(4, rating);
        myStatement.setString(5, descr);
        int insertedOrNot = myStatement.executeUpdate();
        System.out.println("inserted " + insertedOrNot);
    } catch (ClassNotFoundException | SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }finally
    {
        try {
            if(myConnection!=null)
                myConnection.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

}

SEVERE: Servlet.service() for servlet AddMovieServlet threw exception
java.lang.NullPointerException
at wimc.serv.AddMovieServlet.process(AddMovieServlet.java:52)
at wimc.serv.AddMovieServlet.doGet(AddMovieServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at     org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
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:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
4

1 回答 1

0

req.getParameter("relDate")返回空值。

于 2013-05-12T23:40:09.767 回答