我让这段代码在 servlet 中运行
public void doPost(HttpServletRequest request, HttpServletResponse response) {
final HttpServletRequest requestF = request;
Runnable runner = new Runnable() {
public void run() {
String something = requestF.getParameter("anything");
//do other things...
}
};
Thread thread = new Thread(runner);
thread.start();
但是当我尝试从请求对象中获取参数时它会引发异常。
Exception in thread "Thread-25" java.lang.NullPointerException
at org.apache.catalina.connector.Request.parseParameters(Request.java:2560)
at org.apache.catalina.connector.Request.getParameter(Request.java:1086)
at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:355)
at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:158)
at br.com.test.controller.ajax.MyServlet$1.run(MyServlet.java:54)
at java.lang.Thread.run(Thread.java:619)
该requestF
对象不为空,我已经检查过了。有谁知道我是否可以访问新的请求对象Thread
?