加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Struts2动态结果集代码示例

发布时间:2020-12-14 22:24:49 所属栏目:Java 来源:网络整理
导读:动态结果集可以在action中指定要跳转的页面(${}是OJNL表达式,不是EL表达式) struts.xml: package name="resultTypes" namespace="/r" extends="struts-default" action name="result_mul" class="cn.edu.hpu.action.ResultAction" !-- 这种写法代表在配置文

动态结果集可以在action中指定要跳转的页面(${}是OJNL表达式,不是EL表达式)

struts.xml:

<package name="resultTypes" namespace="/r" extends="struts-default"> 
<action name="result_mul" class="cn.edu.hpu.action.ResultAction"> 
<!-- 这种写法代表在配置文件中可以用这种方法去读值栈里面的内容 --> 
  <result>${r}</result> 
</action> 
</package> 

ResultAction.java:

package cn.edu.hpu.action;  
import com.opensymphony.xwork2.ActionSupport; 
public class ResultAction extends ActionSupport {  
  private int type;    
  private String r="/Hello.jsp";    
  public int getType() { 
    return type; 
  }   
  public void setType(int type) { 
    this.type = type; 
  }   
  public String getR() { 
    return r; 
  } 
  public void setR(String r) { 
    this.r = r; 
  } 
  public String execute() throws Exception { 
    //因为r是后来保存在值栈中的,所以能被配置文件以${r} 
    //的形式读到 
    if(type==1) r="/User_Add_success.jsp"; 
    else if(type==2) r="/User_Add_error.jsp"; 
    return SUCCESS; 
  } 
} 

前台链接:

<a href="<%=basePath %>/r/result_mul?type=1" rel="external nofollow" >动态结果集1</a> 
<a href="<%=basePath %>/r/result_mul?type=2" rel="external nofollow" >动态结果集2</a> 
<a href="<%=basePath %>/r/result_mul?type=3" rel="external nofollow" >动态结果集3</a> 

总结

以上就是本文关于Struts2动态结果集代码示例的全部内容,希望对大家学习Struts2有所帮助。感兴趣的朋友可以参阅本站更多相关文章:Struts和servlet不能共存问题解决方法 、 Struts2修改上传文件大小限制方法解析 、 struts2开发流程及详细配置等。有问题的话可以随时留言,小编会及时回复大家的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读