开发者

getting an error page, uploading a file worked last week and I have made no changes

开发者 https://www.devze.com 2023-02-24 22:06 出处:网络
here is my JSF/HTML page <?xml version=\'1.0\' encoding=\'UTF-8\' ?> <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt

here is my JSF/HTML page

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:c="http://java.sun.com/jsp/jstl/core">


<body>


        <ui:composition template="./templates/template.xhtml">
        <ui:define name="content">
            <c:choose>
                <c:when test="#{controls.designAuth}">
                Welcome Report Designer!<br /><br />

                <div id="fileUpload">



                    <form name="myForm" action="../UploadServlet" enctype="multipart/form-data"  method="POST">

                        <b>Make sure your filename is meaningful (eg. WasteByMachineReport.jrxml)</b><br /><br />

                        Please specify a file:<input type="file" name="file" size="40"/><br /><br />
                        Number of parameters: <select name="numSelect" id='numSelect' onchange="draw_param_dropdowns();">
                            <option selected="selected" >0</option>
                                                    <option>1</option>
                                                    <option>2</option>
                                                    <option>3</option>
                                                    <option>4</option>
                                                    <option>5</option>
                                                    <option>6</option>
                                                    <option>7</option>
                                                    <option>8</option>
                                                    <option>9</option>
                                                    <option>10</option>
                                                    <option>11</option>
                                                    <option>12</option>
                                                    <option>13</option>
                                                    <option>14</option>
                                                    <option>15</option>
                                              </select><br />
                                              <br /><br />
                                              <table border="0">
                                                  <tr style="background-color:#dddddd;color:black;"><td><sp开发者_开发技巧an id ="tabletitles" style ="display: none;">Parameter Name</span></td><td><span width="200" id ="tabletitles2" style ="display: none;">Data Type</span></td></tr>

                                                  <tr style="background-color:#dddddd;color:black;"><td>
                                                          <input type="text" name="P1" id="P1" style="display:none;"></input></td><td><select id="Ptype1" name="Ptype1" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                                          </td></tr>
                                             <tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P2" id="P2" style="display:none;"></input></td><td><select id="Ptype2" name="Ptype2" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr> <tr style="background-color:#dddddd;color:black;"><td><input type="text" name="P3" id="P3" style="display:none;"></input></td><td><select id="Ptype3" name="Ptype3" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P4" id="P4" style="display:none;"></input></td><td><select id="Ptype4" name="Ptype4" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P5" id="P5" style="display:none;"></input></td><td><select id="Ptype5" name="Ptype5" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P6" id="P6" style="display:none;"></input></td><td><select id="Ptype6" name="Ptype6" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr> <tr style="background-color:#dddddd;color:black;"><td><input type="text" name="P7" id="P7" style="display:none;"></input> </td><td><select id="Ptype7" name="Ptype7" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P8" id="P8" style="display:none;"></input></td><td><select id="Ptype8" name="Ptype8" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P9" id="P9" style="display:none;"></input></td><td><select id="Ptype9" name="Ptype9" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td><input type="text" name="P10" id="P10" style="display:none;"></input></td><td> <select id="Ptype10" name="Ptype10" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td><input type="text" name="P11" id="P11" style="display:none;"></input></td><td> <select id="Ptype11" name="Ptype11" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td><input type="text" name="P12" id="P12" style="display:none;"></input> </td><td><select id="Ptype12" name="Ptype12" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td><input type="text" name="P13" id="P13" style="display:none;"></input> </td><td><select id="Ptype13" name="Ptype13" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P14" id="P14" style="display:none;"></input></td><td><select id="Ptype14" name="Ptype14" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                             </td></tr><tr style="background-color:#dddddd;color:black;"><td> <input type="text" name="P15" id="P15" style="display:none;"></input></td><td><select id="Ptype15" name="Ptype15" style="display:none;">
                                                                                                   <option>Date</option>
                                                                                                   <option>String</option>
                                                                                                   <option>Number</option></select>
                                              </td></tr></table>
<script type="text/javascript" language="Javascript">


                                                    function draw_param_dropdowns(){

                                                     for (var x = 1; x <= 15; x++) {
                                                            document.getElementById('Ptype' + x).style.display='none';
                                                            document.getElementById('P' + x).style.display='none';

                                                            document.getElementById("tabletitles").style.display = 'none';
                                                            document.getElementById("tabletitles2").style.display = 'none';

                                                        }
                                                                if (document.getElementById("numSelect").selectedIndex >=1)
                                                                    {document.getElementById("tabletitles").style.display = 'block';
                                                                     document.getElementById("tabletitles2").style.display = 'block';}


                                                        for (var y = 1; y <= document.getElementById("numSelect").selectedIndex; y++) {
                                                            document.getElementById('Ptype' + y).style.display = 'block';
                                                            document.getElementById('P' + y).style.display = 'block';
                                                        }
                                                    }


    </script>

                        <input type="submit" value="Upload"/>

                    </form>

                </div>
                </c:when>
                <c:otherwise>
                    Not Authorized 
                </c:otherwise>
            </c:choose>

        </ui:define>

    </ui:composition>

</body>

and here is the java servlet that was like I said working to upload files a week ago or so

/*\_________________________________________________
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
\*///-----------------------------------------------

package DBFunctions;

// Import required java libraries
import java.io.*;
import java.util.*;



import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.output.*;

public class UploadServlet extends HttpServlet {

   private boolean isMultipart;
   private String filePath;
   private int maxFileSize = 200 * 1024;
   private int maxMemSize = 4 * 1024;
   private File file ;
   private String name;
   private String reportTitle;


    @Override
   public void init(){
      // Get the file location where it would be stored.
      filePath = "c:\\Projects\\WebApplication8\\web\\uploads\\";

   }
    @Override
   public void doPost(HttpServletRequest request,
               HttpServletResponse response)
              throws ServletException, java.io.IOException {
      // Check that we have a file upload request



      isMultipart = ServletFileUpload.isMultipartContent(request);
      request.getParameter(null);
      response.setContentType("text/html");
      java.io.PrintWriter out = response.getWriter( );
      if( !isMultipart ){
         out.println("<html>");
         out.println("<head>");
         out.println("<title>Servlet upload</title>");
         out.println("</head>");
         out.println("<body>");
         out.println("<p>No file uploaded</p>");
         out.println("</body>");
         out.println("</html>");

         return;
      }
      DiskFileItemFactory factory = new DiskFileItemFactory();
      // maximum size that will be stored in memory
      factory.setSizeThreshold(maxMemSize);
      // Location to save data that is larger than maxMemSize.
      factory.setRepository(new File("c:\\temp"));

      // Create a new file upload handler
      ServletFileUpload upload = new ServletFileUpload(factory);
      // maximum file size to be uploaded.
      upload.setSizeMax( maxFileSize );

      try{
      // Parse the request to get file items.
      List fileItems = upload.parseRequest(request);

      // Process the uploaded file items
      Iterator i = fileItems.iterator();

      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet Upload</title>");
      out.println("</head>");

      out.println("<body><div style='position:absolute;width:500px;height:700px;left:35%;background-color:#d2d2d2;'><center><br /><br /><br /><br /><br />");
      //out.println(filePath);
      while ( i.hasNext () )
      {
         FileItem fi = (FileItem)i.next();
         if ( !fi.isFormField () )
         {
            // Get the uploaded file parameters
            String fieldName = fi.getFieldName();
            String fileName = fi.getName();
            String contentType = fi.getContentType();
            boolean isInMemory = fi.isInMemory();
            long sizeInBytes = fi.getSize();
            // Write the file
            name = fileName;
            if( fileName.lastIndexOf("\\") >= 0 ){
               file = new File( filePath +
               fileName.substring( fileName.lastIndexOf("\\")));
            }else{
               file = new File( filePath +
               fileName.substring(fileName.lastIndexOf("\\")+1));
            }
            fi.write( file );


            out.println("<br /><br />Uploaded Filename: " + fileName + "<br>");
         }
      }
      out.println("<br /><br /><a href='/WebApplication8/faces/it.xhtml'>Add New File to / Edit Menu Tree</a><br /><br /><br />");
      out.println("<a href='/WebApplication8/faces/designer.xhtml'>Back</a></center></div>");

      //-------------------------------------------------------------------------

//            String params  =request.getParameter("numParams");
//
//
//             int numParams = Integer.parseInt(params);
//
//            out.println(numParams);

            DBConnect db = new DBConnect();

            boolean result = db.DBConnectAndUpdate("INSERT INTO PLANT.APPLIC VALUES (9999, '" + name + "','R','" + "',0,'eng')");


      //-------------------------------------------------------------------------



      out.println("</body>");
      out.println("</html>");


   }catch(Exception ex) {
       System.out.println(ex.getMessage());
   }

   }
    @Override
   public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
        throws ServletException, java.io.IOException {

        throw new ServletException("GET method used with " +
                getClass( ).getName( )+": POST method required.");
   }
}

and here is the error

I have looked at the error and looked through the entire servlet for missing semi colons or something silly, but I haven't made any changes literally since the last time it worked

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
    java.util.Hashtable.get(Hashtable.java:334)
    org.apache.tomcat.util.http.Parameters.getParameterValues(Parameters.java:195)
    org.apache.tomcat.util.http.Parameters.getParameter(Parameters.java:240)
    org.apache.catalina.connector.Request.getParameter(Request.java:1066)
    org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:355)
    org.netbeans.modules.web.monitor.server.MonitorRequestWrapper.getParameter(MonitorRequestWrapper.java:199)
    DBFunctions.UploadServlet.doPost(UploadServlet.java:54)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.


From your servlet code:

request.getParameter(null);

A few steps into this method call java.util.Hashtable.get(null) gets called, which throws the NPE. This is the expected behavior, see java.util.Hashtable.get(Object), because null as a key is not allowed for a Hashtable. This is exactly what the Stacktrace tells you. If it worked before, the code must have changed somehow because this line will always fail, and it would have failed a few weeks or months ago, too. (And it doesn't make too much sense in the first place).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号