2013-06-22 137 views
0

我想通過多個隱藏參數從jspservlet。 當我這樣編碼。它拋出錯誤如何將多個隱藏參數從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 
+0

很難理解提供大量信息的問題。如果你可以發佈完整的異常日誌和你的表單標記更多一點 –

+0

Ankit,沒有任何不同的方法來訪問servlet中的隱藏參數比正常參數。我在你之前的問題中已經解釋了這一點。 JasperException是由於其他問題導致的。你需要發佈所有代碼和stracktrace –

+0

感謝朋友的幫助。在這裏我發佈了簡短的代碼和例外。我無法診斷問題,即如何將多個隱藏參數從jsp發送到servelt。 –

回答

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


請檢查這部分後,您的 '類別' 的對象。我認爲它仍然是空的。請不要使用這個錯誤和隱藏的參數。發生此錯誤是因爲嘗試訪問空對象。

+2

你可以提供評論來做到這一點,你不需要寫這個東西作爲答案 –

+0

對不起我在這裏新。我不能看到添加評論問題的鏈接。 – pikrut

+0

@Pikrut。你是絕對正確的。我犯了這個愚蠢的錯誤。現在我的問題解決了。謝謝朋友。 :) –