不明白这里?
com.zrcx.controller.DepartmentController.add(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) at java.lang.Class.getMethod(Class.java:1786) at global.DispatcherServlet.service(DispatcherServlet.java:58) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at global.EncodingFilter.doFilter(EncodingFilter.java:33) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
0
收起
正在回答 回答被采纳积分+1
4回答
qq_蓝骏毅_04076633
2018-11-29 15:22:30
他现在哪里不行
qq_蓝骏毅_04076633
2018-11-29 15:21:54
还是不明白
qq_蓝骏毅_04076633
2018-11-29 14:25:51
package global; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.servlet.GenericServlet; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class DispatcherServlet extends GenericServlet{ private ApplicationContext applicationContext; public void init() throws ServletException { super.init(); applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml"); } @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; /* staff/add.do login.do staffController public void add(HttpServletRequest request, HttpServletResponse response){} * */ String path = request.getServletPath().substring(1); String beanName = null; String methodName = null; int index = path.indexOf("/"); if(index!=-1) { beanName=path.substring(0,index)+"Controller"; methodName = path.substring(index+1,path.indexOf(".do")); }else { beanName="staffController"; methodName=path.substring(0,path.indexOf(".do")); } Object obj = applicationContext.getBean(beanName); try { Method method = obj.getClass().getMethod(methodName,HttpServletRequest.class,HttpServletResponse.class); method.invoke(obj,request,response); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } }
qq_蓝骏毅_04076633
2018-11-29 14:24:37
package com.zrcx.controller; import java.io.IOException; import java.util.List; import javax.annotation.Resource; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import com.zrcx.entity.Department; import com.zrcx.service.DepartmentService; @Controller("departmentController") public class DepartmentController { //注入service @Resource private DepartmentService departmentService; // /department/list.do /department_list.jsp //控制器 public void list(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { //欧所有部门信息 List<Department> list = departmentService.getAll(); request.setAttribute("LIST", list); request.getRequestDispatcher("../department_list.jsp").forward(request, response); } //添加部门信息 public void toAdd(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { //转发到department_add.jsp request.getRequestDispatcher("../department_add.jsp").forward(request, response); } //实际添加 public void Add(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); String address = request.getParameter("arrdess"); Department department = new Department(); department.setName(name); department.setName(address); departmentService.add(department); //转发 response.sendRedirect("list.do"); } }
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星