samespace 0 Newbie Poster

Hi! I recently started learning how to implement MVC. I'm supposed to update a photo caption, but whenever I hit the "Update!" button, an error message appears saying, "The server encountered an internal error () that prevented it from fulfilling this request."

note: i'm using netbeans 6.5

This is in the <head> of the my jsp file, editphoto.jsp

<%  if(session.getAttribute("user")!=null)
            {
                Entities.User user = (Entities.User) session.getAttribute("user");
                Entities.Album a = (Entities.Album) request.getAttribute("album");
                Entities.Photo p = (Entities.Photo) request.getAttribute("photo");
                Entities.User view = user;
        %>

This is the text field for editing the caption

<input type="text" id="caption" name="caption" value="<%= p.getCaption()%>" onfocus="this.select()">

This is part of the Controller, "PhotoUpdate.java"

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        //PrintWriter out = response.getWriter(); for some reason, the code wouldn't work if I use this.
        try {
         HttpSession s = request.getSession();

         Entities.Photo p = (Entities.Photo) s.getAttribute("photos");
         p.setCaption(request.getParameter("caption"));
         Entities.PhotoManager.savePhoto(p);

         ServletContext sc = getServletContext();
         RequestDispatcher rd = sc.getRequestDispatcher("/viewphotoprofile.jsp"); //this is supposed to go to the page which displays the photo, with its caption updated
         rd.forward(request, response);

        } finally {
            //out.close();
        }

    }

Also, when I retrieved the data from the database into the text field, my other controller (called PhotoUpdatePrepare.java) didn't need PrintWriter. It wouldn't work at all if I used it. It's strange, because when making the code for updating the user profile, PrintWriter is used and it worked. I only copied most of the things needed in updating user profile to the codes in updating a photo caption.

Again, I'm new to MVC. I'm only a student and this is for our web development class. Any help would be greatly appreciated, and I am still tracing where I could go wrong up until now.

- Murphy

error stack from apache tomcat log:

Mar 31, 2009 8:45:46 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet photoUpdate threw exception
java.lang.NullPointerException
at Control.photoUpdate.processRequest(photoUpdate.java:40)
at Control.photoUpdate.doGet(photoUpdate.java:62)
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.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:128)
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:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)