ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:97.55KB ,
资源ID:23275223      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23275223.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(struts221 + spring 305 配置与测试例子.docx)为本站会员(b****1)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

struts221 + spring 305 配置与测试例子.docx

1、struts221 + spring 305 配置与测试例子一、配置Struts1、本配置与测试例子,使用MyEclipse 6.0.1版本软件,创建web工程。2、把struts 2.2.1的相关jar添加到工程中,如图所示。1)选择Add External Archives2)选择jar包Struts 2.2.1核心所包含的文件有8个jar文件,如下图所示。3、添加配置文件配置文件包括struts.xml和web.xml,两者路径分别为:1)struts.xml:src根目录下。在没有配置之前文件内容如下:2)web.xml:WEB-INF目录下。在没有配置之前,文件内容如下:web-ap

2、p version=2.5 xmlns= xmlns:xsi=http:/www.w3.org/2001/XMLSchema-instance xsi:schemaLocation= index.jsp 该web.xml是创建web工程的时候产生的。在struts2.2中,该文件改为:web-app version=2.5 xmlns= xmlns:xsi=http:/www.w3.org/2001/XMLSchema-instance xsi:schemaLocation= struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepa

3、reAndExecuteFilter struts2 /* index.jsp 4、添加处理业务流程1)添加业务页面,如添加信息页面 Login 这里的页面,使用了struts的标签。主要有username与password两个字段,以及form的名称为login。2)添加Action类添加的Action,继承了ActionSupport,也可以直接实现Action接口。这里的两个字段与页面使用的标签相对应。这里重载了execute函数,该函数作为默认的Action的处理函数。在实现Action接口,必须进行处理。package com.gsww.kingreturns.struts2.exc

4、ise;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport /该类继承了ActionSupport类。这样就可以直接使用SUCCESS, LOGIN等变量和重写execute等方法 private static final long serialVersionUID = 1L; private String username; private String password; public String getUsername() return username;

5、 public void setUsername(String username) this.username = username; public String getPassword() return password; public void setPassword(String password) this.password = password; Override public String execute() throws Exception if(haha.equals(username) & hehe.equals(password)/如果登录的用户名=haha并且密码=heh

6、e,就返回SUCCESS;否则,返回LOGIN return SUCCESS; return LOGIN; 3)配置struts.xml文件在xml文件中,添加package内容(如果已经存在,不用再添加)。接着添加action,这里action的name与页面上的form名称一致;class就是Action类;method为Action执行的函数,一般为execute方法。在execute中,使用到SUCCESS以及LOGIN常量,这些在Action基类中定义。这里需要说明下一步分别执行的页面。 /welcome.jsp /login.jsp 4)定义welcome.jsp和login.js

7、p页面(存放在WebRoot目录下)下面为welcome.jsp页面,直接使用了标签简化。 My JSP welcome.jsp starting page 欢迎$username ! 二、配置Spring1、添加jar包本次使用的Spring版本为3.0.5,因此,需要把spring-framework-3.0.5.RELEASE.zip中的jar全部添加,共20个jar。另外,需要Struts和Spring整合的jar,这里使用struts2-spring-plugin-2.2.1.jar。2、修改web.xml文件,添加Spring的监听器ContextLoaderListener,具体

8、文件内容如下: org.springframework.web.context.ContextLoaderListener struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* 注意:这里的其实是指向applicationContext.xml文件的,当之有一个该文件时候,把它放在WEB-INF下即可。如果存在多个文件的时候,需要说明文件路径。在监听器上面添加配置: contextConfigLocation /WEB-INF/classes/applicationCon

9、text.xml,/WEB-INF/daoContent.xml3、使用Spring方法一:1)添加Spring层处理函数添加接口package com.gsww.kingreturns.struts2.service;public interface TestService boolean ValidPassword(String name, String pwd);接口实现package com.gsww.kingreturns.struts2.service.impl;import com.gsww.kingreturns.struts2.service.TestService;publ

10、ic class TestServiceImp implements TestService public boolean ValidPassword(String name, String pwd) / TODO Auto-generated method stub if(name.equals(wendehai) & pwd.equals(123) return true; return false; 2)Action中添加逻辑处理添加字段ts,并且实现其setter函数。并在execute中,添加ts的调用。package com.gsww.kingreturns.struts2.exc

11、ise;import com.gsww.kingreturns.struts2.service.TestService;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport / 该类继承了ActionSupport类。这样就可以直接使用SUCCESS, / LOGIN等变量和重写execute等方法 private static final long serialVersionUID = 1L; private String username; private St

12、ring password; private TestService ts; public void setTs(TestService ts) this.ts = ts; public String getUsername() return username; public void setUsername(String username) this.username = username; public String getPassword() return password; public void setPassword(String password) this.password =

13、 password; Override public String execute() throws Exception if(ts.ValidPassword(this.username, this.password) return SUCCESS; else return LOGIN; 3)设置配置文件applicationContext.xml中添加对于Spring处理类的配置 这里说明了Action的名字loginAction,需要把struts.xml中的class名字改loginAction,而不是实际的类路径。 /welcome.jsp /login.jsp /info.jsp /error.jsp 方法二:该方法与方法一的区别在于配置文件设置不同。applicationContext.xml中,Spring处理类,配置为如下,这里的id值需要与Action中的变量名字一致,即为ts。 Struts.xml中,Action使用实际路径,其它不变

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1