1、servlet总结1. jsp编译后就是servlet:tomcat-work-jsp2. jsp页面加载或创建时就为我们创建了session,可以设置为falsepublic class ZmxServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException /response.setContentType(text/html); doPost(request, response
2、); public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.getSession().setAttribute(username,zmx); request.getRequestDispatcher(show.jsp).forward(request, response); ZmxServlet com.zmx.action.ZmxServlet ZmxServlet /ZmxServlet singlet
3、on单例模式: * 懒汉式 * 饿汉式 * 构造方法必须是私有化/* * * 饿汉式 * */public class Singleton private final static Singleton instance = new Singleton(); /必须私有化 private Singleton() public static Singleton getInstance() return instance; /* * * 懒汉式 * */public class SingletonA private static SingletonA instance = null; / 必须私有化
4、 private SingletonA() public static SingletonA getInstance() if (instance = null) instance = new SingletonA(); return instance; * is-a class A impl B 实现了接口B的所有方法 interface B * is-like-a class A impl B 实现了接口B的所有方法,且含有自己特有的其他方法 interface B * has-a class A impl B private B b; class B 导入代码模板: window-pre
5、ference-code template-commons -files-imp-复选框 * 修改三处user,设置成自己的名字 * oracle1521 * mySql3306 * sqlServer 1433mvc: * 反射:就是在运行期间获取对象信息 public static void main(String args) throws Exception /TUser user = new TUser();第一种 /第二种TUser user = (TUser) Class.forName(com.zmx.domain.TUser).newInstance(); /ClassLoad
6、er cl = new ClassLoader() ;第三种 /TUser user = (TUser) cl.loadClass(com.zmx.domain.TUser).newInstance(); TUser user = TUser.class.newInstance();/第四种 System.out.println(user.getUsername(); - public static void main(String args) throws Exception TUser user = (TUser) Class.forName(com.zmx.domain.TUser).n
7、ewInstance(); /获取共有的方法/ Method method = user.getClass().getMethod(setUsername, String.class);/ method.invoke(user, lisi);/ System.out.println(user.getUsername(); /获取所有的方法 Method methods = user.getClass().getDeclaredMethods(); for(int i=0;imethods.length;i+) /获取方法名称 /System.out.println(methodsi); /获取方法对应的类型 System.out.println(methodsi.getReturnType(); - 1 servlet作为前端控制器:获取uri后截取url 读取xml配置文件-初始化 获取配置文件中的属性:name class method 通过反射获取对象 加入对象 map.put(name, actionInstance); map.put(method, methodName); 获取uri后截取url * 导入dom4j和jaxen frontFilter com.zmx.util.FrontFilter frontFilter *.do REQUEST FORWARD
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1