servlet总结.docx

上传人:b****8 文档编号:9199646 上传时间:2023-02-03 格式:DOCX 页数:7 大小:15.40KB
下载 相关 举报
servlet总结.docx_第1页
第1页 / 共7页
servlet总结.docx_第2页
第2页 / 共7页
servlet总结.docx_第3页
第3页 / 共7页
servlet总结.docx_第4页
第4页 / 共7页
servlet总结.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

servlet总结.docx

《servlet总结.docx》由会员分享,可在线阅读,更多相关《servlet总结.docx(7页珍藏版)》请在冰豆网上搜索。

servlet总结.docx

servlet总结

1.jsp编译后就是servlet:

tomcat-->work-->jsp

2.jsp页面加载或创建时就为我们创建了session,可以设置为false

 

publicclassZmxServletextendsHttpServlet{

 

publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException{

//response.setContentType("text/html");

doPost(request,response);

}

publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException{

request.getSession().setAttribute("username","zmx");

request.getRequestDispatcher("show.jsp").forward(request,response);

}

}

 

ZmxServlet

com.zmx.action.ZmxServlet

ZmxServlet

/ZmxServlet

 

singleton单例模式:

*懒汉式

*饿汉式

*构造方法必须是私有化

/**

*

*饿汉式

*

*/

publicclassSingleton{

privatefinalstaticSingletoninstance=newSingleton();

//必须私有化

privateSingleton(){}

publicstaticSingletongetInstance(){

returninstance;

}

}

 

/**

*

*懒汉式

*

*/

publicclassSingletonA{

privatestaticSingletonAinstance=null;

//必须私有化

privateSingletonA(){

}

publicstaticSingletonAgetInstance(){

if(instance==null)

instance=newSingletonA();

returninstance;

}

}

 

*is-a

classAimplB{

实现了接口B的所有方法

}

interfaceB{

}

*is-like-a

classAimplB{

实现了接口B的所有方法,且含有自己特有的其他方法

}

interfaceB{

}

*has-a

classAimplB{

privateBb;

}

classB{

}

导入代码模板:

window-->preference-->codetemplate--->commons

--->files-->imp-->复选框

*修改三处user,设置成自己的名字

*oracle1521

*mySql3306

*sqlServer1433

 

mvc:

*反射:

就是在运行期间获取对象信息

publicstaticvoidmain(String[]args)throwsException{

//TUseruser=newTUser();第一种

//第二种TUseruser=(TUser)Class.forName("com.zmx.domain.TUser").newInstance();

//ClassLoadercl=newClassLoader(){};第三种

//TUseruser=(TUser)cl.loadClass("com.zmx.domain.TUser").newInstance();

TUseruser=TUser.class.newInstance();//第四种

System.out.println(user.getUsername());

}

-----------------------------------------------------------------------------------------

publicstaticvoidmain(String[]args)throwsException{

TUseruser=(TUser)Class.forName("com.zmx.domain.TUser").newInstance();

//获取共有的方法

//Methodmethod=user.getClass().getMethod("setUsername",String.class);

//method.invoke(user,"lisi");

//System.out.println(user.getUsername());

//获取所有的方法

Method[]methods=user.getClass().getDeclaredMethods();

for(inti=0;i

//获取方法名称

//System.out.println(methods[i]);

//获取方法对应的类型

System.out.println(methods[i].getReturnType());

}

}

-----------------------------------------------------------------------------------------

1servlet作为前端控制器:

获取uri后截取url

读取xml配置文件-初始化

获取配置文件中的属性:

nameclassmethod

通过反射获取对象

加入对象

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