0

我想将多个隐藏参数从jsp传递给servlet。当我这样编码时。它抛出错误

Here is the code and exception

<% ProductCategoryDAO categoryDAO=new ProductCategoryDAO();
    ProductCategory category=null;
    if(request.getParameter("catogoryId")!=null){
    category=categoryDAO.findById(Integer.valueOf(request.getParameter("catogoryId")));
    }
     %>
     <form action="AdminController" method="POST" name="frmaddProductCategory"  >
        **<input type="hidden" name="categoryAction" value="editProductCategory">**
        <h1 align="center">Product Category Details</h1>
        <fieldset>
            <legend>Product Category</legend>
            <ul>
            <li>**<input type="hidden" name="categoryId" id="categoryId"  readonly="readonly"
                    value="<%=category.getProductCategoryId() %>"/>**
                </li>
                <li><label for="categoryCode">Category Code</label> <input
                    type="text" name="categoryCode" id="categoryCode" required="required" maxlength="12" readonly="readonly"
                    value="<%=category.getProductCategoryCode() %>"/>
                </li>
                <li><label for="categoryName">Category Name</label> <input type="text"
                    name="categoryName" id="categoryName" required="required" autofocus="autofocus" maxlength="100" 
                    value="<%=category.getProductCategoryName() %>"/>
                </li>
                <li><label for="description">Description</label> <input
                    type="text" name="description" id="description" maxlength="500" value="<%=category.getDescription() %>"/>
                </li>

            </ul>
        </fieldset>
        <input type="submit" name="submit" value="Update Category">
    </form>

例外:

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jsp.editProductCategory_jsp._jspService(editProductCategory_jsp.java:133)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
    at bnms.controllers.admin.AdminController.doGet(AdminController.java:346)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    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:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Jun 22, 2013 3:40:12 PM org.apache.catalina.core.StandardWrapperValve invoke
4

1 回答 1

1
<% ProductCategoryDAO categoryDAO=new ProductCategoryDAO();
    ProductCategory category=null;
    if(request.getParameter("catogoryId")!=null){
    category=categoryDAO.findById(Integer.valueOf(request.getParameter("catogoryId")));
    }
     %>


请在这部分之后检查您的“类别”对象。我认为它仍然为空。请不要纠结这个错误和隐藏参数。由于尝试访问空对象而发生此错误。

于 2013-06-22T10:04:21.923 回答