该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
servlet跳转总是出来这个反射异常还有空指针 而且每个servlet里都报一个空指针的错 应该就是反射的问题
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.bs.servlet.backend.BaseServlet.service(BaseServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at org.bs.servlet.backend.StaffServlet.add1(StaffServlet.java:136)
... 27 more
这是空指针的代码
public void add1(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, IllegalAccessException,
InvocationTargetException {
Staff staff = ResultUtils.copyParams(Staff.class, request);
User user = new User();
BeanUtils.copyProperties(user, staff);
user.setRole(staff.getRoles());
String password = request.getParameter("password");
user.setPassword(password);
userService.add(user);//这行报空指针 我改成下面的就不报了 可以跳转 不过就不能把信息加到数据库了
//request.setAttribute("user", user);
staff.setUsers(user);
staffService.add(staff);//这个也是一样的 报空指针 我感觉就是反射的事
//request.setAttribute("staff", staff);
request.getRequestDispatcher("/backend/staff/add_staff_success.jsp")
.forward(request, response);
}
反射的部分代码
if (!DiInited) {
BeanFactory factory = (BeanFactory) this.getServletContext()
.getAttribute("beanFactory");
Method[] methods = this.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
String DIMethodName = methods[i].getName();
if (DIMethodName.startsWith("set")) {
String beanName = DIMethodName.substring(3, 4)
.toLowerCase() + DIMethodName.substring(4);
try {
methods[i].invoke(this, factory.getBean(beanName));//有的servlet跳转这行也报空指针
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
DiInited = true;
try {
Method method = this.getClass().getMethod(
methodName,
new Class[] { HttpServletRequest.class,
HttpServletResponse.class });
method.invoke(this, request, response);//at org.bs.servlet.backend.BaseServlet.service(BaseServlet.java:60)
} catch (Exception e) {
e.printStackTrace();
}
PageContext.remove();
}