1、概述
2、Model 1 和 Model 11
3、MVC模式
4、开发基于MVC模式的应用程序
转发:
重定向:
5、自定义MVC框架的实现
两种取路径名称的方式:
事例:http://localhost:8181/news/jsp/dispose.jsp
String uri = request.getRequestURI();
System.out.println(uri);
String contextPath = request.getContextPath();
System.out.println(contextPath);
String contextPathAfter = uri.substring(contextPath.length());
System.out.println(contextPathAfter);
String realName = contextPathAfter.substring(1, contextPathAfter.lastIndexOf(".")).trim();
System.out.println(realName);
执行结果:
/news/jsp/dispose.jsp
/news
/jsp/dispose.jsp
jsp/dispose
注:不太理想,倒可以学学。
String uri = request.getRequestURI();
String name = new File(uri).getName();
System.out.println(name);
String actionName = name.substring(0, name.lastIndexOf(".")).trim();
System.out.println(actionName);
执行结果:
dispose.jsp
dispose
注:紧凑,推荐使用
注:action获取页面请求,并调用模型,返回要跳转的视图的字符串。
getAction()方法,根据页面请求的uri决定实例化哪个action,返回action对象。
doGet()方法,根据实例化的action,调用action的execute()方法,获取返回的的视图字符串,跳转相应页面。
小结: