在 method=request.getParameter("value") 上得到空值;

问题描述 投票:0回答:0

我在这条 java 行的 servlet 中遇到空错误

String method = request.getParameter("method");
尝试了多种方式,比如在 post 方法中发送数据(
method="POST"
)但仍然无法正常工作不知道是什么导致了单击按钮 js 被调用的问题这里就不贴了。

<html:form action="/Example.do">
  <html:hidden property="method" value="someBegin" />
  
  <input 
    type="button" 
    value="Next"
    onClick="javascript:submit();">
  </input>
</html:form>

在下面的 Java 文件中,当我调试它时,我得到的方法为空,它发现空方法字符串变量。

public final class TestForm
  extends ValidatorActionForm 
  implements Serializable {
  
  public ActionErrors test(ActionMapping mapping,HttpServletRequest request) {
    String method = request.getParameter("method");
    return method;
  }
}

错误日志

ERROR [http-nio-9495-exec-3] o.a.c.c.C.[.[.[.[.t.e.c.ExampleActionServlet] - Servlet.service() for servlet [com.example.ExampleActionServlet] in context with path [/demo] threw exception
java.lang.NullPointerException: null
    at com.example.TestForm.test(TestForm.java:23) ~[classes!/:1.22.0.129305]
    at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:950) ~[struts-1.2.9.jar!/:1.2.9]
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:207) ~[struts-1.2.9.jar!/:1.2.9]
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) ~[struts-1.2.9.jar!/:1.2.9]
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) ~[struts-1.2.9.jar!/:1.2.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:528) ~[tomcat-embed-core-9.0.73.jar!/:?]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:596) ~[tomcat-embed-core-9.0.73.jar!/:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209) ~[tomcat-embed-core-9.0.73.jar!/:?]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.73.jar!/:?]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.73.jar!/:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.73.jar!/:?]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.73.jar!/:?]

不明白这里出了什么问题,所以需要一些帮助。没有包含更多代码,因为它很长

我尝试在 html 隐藏标签中添加

method="POST"
但它仍然没有任何建议或可能有问题。

struts-1
© www.soinside.com 2019 - 2024. All rights reserved.