日期:2014-05-18  浏览次数:20621 次

struts中,我在jsp页面中设置了abc.do?bh=1&operate=2,我如何在action中得到这两个参数值呢?
struts中,我在jsp页面中设置了abc.do?bh=1&operate=2,

我如何在action中得到这两个参数值呢?

struts-config.xml中如何配置,action中如何写代码得到这两个参数的数值呢?

请高手帮忙

------解决方案--------------------
String bh = request.getParameter( "bh ");
String operate = request.getParameter( "operate ");
------解决方案--------------------
action中那个方法应该会传入HttpServletRequest对象。
用楼上的方法就可以取到

------解决方案--------------------
struts是对servlet的封装,以前在servlet中怎么取现在在action中还是怎么取,一楼的方法就可以了

另外一种方法就是将参数对应到formbean,在action中通过ActionForm取
struts-config配置文件片段
<form-bean name= "form1 " type= "org.apache.struts.action.DynaActionForm ">
<form-property name= "bh " type= "java.lang.String "/>
<form-property name= "operate " type= "java.lang.String "/>
</form-bean>

<action path= "/abc "
type= "com.xxx "
name= "form1 "
scope= "request ">
<forward name= "success " path= "/xxx.jsp "/>
</action>

action的execute方法
DynaActionForm myForm = (DynaActionForm)form;
String bh = (String)myForm.get( "bh ");
String operate = (String)myForm.get( "operate ");

ok~~ lz给点分,写这么多不容易