使用Webwork URL参数解析功能

用过struts的朋友都知道,如果我们需要在jsp中加参数,必须一个一个的写上去,如果参数是从action中传过来的,我们必须先在action中把参数保存到request中,然后jsp中取得这个参数,拼凑url

现在,webwork的url参数解析功能,可以动态的生产url

我们的action

其中有一个id=123

package  ch7.example2;

import  com.opensymphony.xwork.ActionSupport;

public   class  TestURLParem  extends  ActionSupport  {

    
private String id;
    
public String getId() {
        
return id;
    }

    
public void setId(String id) {
        
this.id = id;
    }

    
public String execute() throws Exception {
        
this.setId("123");
        
return SUCCESS;
    }


}


我们的jsp

主要是显示传来的id数值

<% @ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding
="GB18030"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
<%
   
String id=request.getParameter("id");
   out.println(id);
 
%>
</ body >
</ html >


最重要的xwork.xml

从action跳转到页面,但是加了一个参数id=${id},我们在action中的id=123,这里的url会解析成
/ch7/param.jsp?id=123

值得注意的是,我们要想使用这个功能,必须设置type="redirect"

  < action  name ="testparam"  class ="ch7.example2.TestURLParem" >
    
< result  name ="success"  type ="redirect" > /ch7/param.jsp?id=${id} </ result >
  
</ action >

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值