前言:
在项目开发过程中的一点点指导思想
创建一个表,对该表进行增删改查
create database XXX;
create table XXX ();
//1 获取servlet路径 诸如:/add.do
String servletPath=req.getServletPath().substring(1);
//去除/和.do得到类似于add这样字符串
String methodName=servletPath.substring(0,servletPath.length()-3);
//System.out.println(methodName);
try {
//利用反射获取获取methodName对应的方法
Method method = getClass().getDeclaredMethod(methodName, HttpServletRequest.class,HttpServletResponse.class);
//利用反射获取方法
method.invoke(this, req,resp);
} catch (Exception e) {
//出错时候响应出来
resp.sendRedirect("error.jsp");
}
对于request、response 的编码问题
在servlet 中跳转页面,我们需要将后台的对象在传回前台,可以用 request.setAttribute(name,value);
原文:http://www.cnblogs.com/panie2015/p/5574550.html