|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
通过视频学习比传统的大课堂学习更适合成人化的学习规律。有人说大课堂气氛好,学习氛围浓,热闹,可以认识很多人。
在说Struts1之前,我们先来利用Servlet编写一个程序从而懂得Struts发生缘故原由和用处:一个复杂的增删改查,我们来看一下利用Servlet是怎样完成的,为了抽象申明,我们从最基础的入手下手写,然后慢慢递进。
初版
这一版我们利用最惯例的做法,增编削查每一个功效都利用本人的Servlet,内容以下:
文件树
index.jsp- <form
- action="servlet/AddUserServlet"method="post">
- 姓名:<inputtype="text"name="username"/><br/>
- <inputtype="submit"value="submit"/>
- </form>
复制代码 Servlet
为了便利申明此处的四个Servlet内容基础不异,此处以AddUserServlet和DelServlet为例:
AddUserServlet- packagecom.tgb.struts1.servlet;
- importjava.io.IOException;
- importjavax.servlet.ServletException;
- importjavax.servlet.http.HttpServlet;
- importjavax.servlet.http.HttpServletRequest;
- importjavax.servlet.http.HttpServletResponse;
- publicclassAddUserServletextendsHttpServlet{
- @Override
- protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
- throwsServletException,IOException{
- Stringusername=request.getParameter("username");
- UserManageruserManager=newUserManager();
- userManager.add(username);
- request.getRequestDispatcher("/add_success.jsp").forward(request,response);
- }
- @Override
- protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
- throwsServletException,IOException{
- doGet(request,response);
- }
- }
复制代码 DelUserServlet- packagecom.tgb.struts1.servlet;
- importjava.io.IOException;
- importjavax.servlet.ServletException;
- importjavax.servlet.http.HttpServlet;
- importjavax.servlet.http.HttpServletRequest;
- importjavax.servlet.http.HttpServletResponse;
- publicclassDelUserServletextendsHttpServlet{
- @Override
- protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
- throwsServletException,IOException{
- Stringusername=request.getParameter("username");
- UserManageruserManager=newUserManager();
- userManager.del(username);
- request.getRequestDispatcher("/del_success.jsp").forward(request,response);
- }
- @Override
- protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
- throwsServletException,IOException{
- doGet(request,response);
- }
- }
复制代码 UserManager
仿照逻辑处置层和数据处置层- packagecom.tgb.struts1.servlet;
- importjava.util.ArrayList;
- importjava.util.List;
- publicclassUserManager{
- publicvoidadd(Stringusername){
- System.out.println("userManager------->add,username="+username);
- }
- publicvoiddel(Stringusername){
- System.out.println("userManager------->del,username="+username);
- }
- publicvoidmodify(Stringusername){
- System.out.println("userManager------->modify,username="+username);
- }
- publicListquery(Stringusername){
- System.out.println("userManager------->query,username="+username);
- ListuserList=newArrayList();
- userList.add("a");
- userList.add("b");
- returnuserList;
- }
- }
复制代码 <p>
用winrar打包j2ee的程序和用IDE打包应用程序是一样的。按照你的想法,你是不是也希望服务器都整合由一家公司提供呢? |
|