不明白这里?

不明白这里?

 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)


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

4回答
提问者 qq_蓝骏毅_04076633 2018-11-29 15:22:30

他现在哪里不行

  • emmm,其实有点不太明白同学的问题,同学是说报错了么?如果是,报错信息是不是没有贴完整呢?建议同学再描述一下,同学具体是对哪里不明白呢?以便于更有针对性的解决同学的问题。
    2018-11-29 16:01:31
  • 提问者 qq_蓝骏毅_04076633 #2
    解决了错误信息!
    2018-11-29 16:02:43
  • 好的,同学的意思是解决了是么?祝学习愉快
    2018-11-29 16:04:36
提问者 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();
        }
		
	}
			
}


  • 你好同学,是不了解DispatcherServlet这个类的作用吗?如果是,这个类的作用是分配器的意思,通过处理前端发送过来的请求,然后利用反射技术来调用控制器中的方法,同学如果有什么不明白的地方可以继续提问,祝学习愉快~​
    2018-11-29 15:19:05
提问者 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");
	}
	
}


问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星

相似问题

登录后可查看更多问答,登录/注册

SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师