今天开始看struct ,在理解struct 的实现过程中,开始主要应用struct的action对象去实现不同功能选择,想起了servlet和jsp不同的跳转方式,为了这三个的理解以及对框架好处的体会,写一篇博客看一看。
一、对于三个显示页面的方式,所依赖的东西与实现方式的不同,这里大概复习一下
servlet:我们用servlet实现一个页面,新建一个servlet,然后web.xml中会进行servlet的 注册,servlet中有页面的书写方式
我们利用servlet中<url-pattern>的值进入访问servlet,servlet显示页面
jsp:jsp可以看做一种servlet,jsp就是可以嵌套java代码的,用EL表达式或者隐含对象进行页面的书写,通过jsp文件的名称访 问jsp文件
struct:struct的核心就是过滤器,用struct封装的对象进行url的判断,进行页面的跳转
二、servlet实现不同功能(利用反射)
package web.servlet;
import java.io.IOException;
import java.lang.reflect.Method;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public abstract class BaseServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String methodName = request.getParameter("method");
System.out.println(methodName);
if(methodName ==null||methodName.trim().isEmpty()){
System.out.println("方法五参数");
throw new RuntimeException("五参数");
}
// if(methodName.equals("addUser")){
// addUser(request,response);
// } else if(methodName.equals("editUser")){
// editUser(request,response);
// }
Class c = this.getClass();
Method method =null;
try {
method = c.getMethod(methodName,HttpServletRequest.class,HttpServletResponse.class);
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catc