一个Strus2的简单示例(核心控制器 StrusPrepareAndExecuteFilter)

1项目结构图如下

计算机生成了可选文字: Strus Demo  Deployment Descriptor: Strus_Demo  'AX-WS Web Services  Java R  esou rces  dB (default package)  Log i nActio nja va  struts.xml  Libraries  Apache Tomcat v8.O [Apache Tomcat  EAR Libraries  'RE System Library  üdkl .8.0_60]  Web App Libraries  JavaScript Resources  build  WebContent  B META-INF  e, WEB-INF  a  aboutus  error.Jsp  Loginjsp  D logn.jsp  TEST_chapterI

 

web.xml下加入如下内容(strus2的核心过滤器

计算机生成了可选文字: < fi Iter>  org . apache . struts2 . dispatcher . ng . fi Iter . StrutsPrepareAndExecuteFiIter  < / fi Iter>  <urI —pattern>

jsp文件引入标签


配置action执行其中的execute()方法返回一个字符串类型

计算机生成了可选文字: prefix= "s" uri= "/struts—tags"  < ! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/ /EN" "http:      form  textfield name= "account"  textfield name= "password" key—  < s: submit  < / s : form)

配置strus.xml文件

计算机生成了可选文字: import com.opensymphony.xwork2 . Actionsupport;  public class Lo inAction extends ctionSupport  rung ac  ate String passwo  public String get Password ( )  return password;  public void setPassword (String password)  this . pas sword  password;  public String getAccount ( )  return account;  public void setAccount (String account)  this . account  account ,  verrx e  public String execute ( ) throws Exception {  if (getAccount ( ) . equal  2345 ( )  return " success '  . equals ("  12345") )  re turn  error'

2)运行效果如下


当输入账号和密码错误时:



当输入正确时:

计算机生成了可选文字: Download a Release  web.xml  -5 C t localhost  = - Powered by... 00 Genymotion 'L  success!  Apac

 

标注:

使用该框架后,较为完美的解决了输入地址就能访问网页的弊端,所有的网页后缀以.action结尾。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值