控制层action获取jsp传递过来的参数有哪几种:

1、通过request获取;
HttpServletRequest request = ServletActionContext.getRequest();
String pid = request.getParater("Pid");
2、在action中分别定义表单的属性,然后set,get方法,即可获取jsp传递过来的数据;
private String pid ;
private String pname;

//省略set,get方法...
private Log log = LogFactory.getLog(HelloAtion.class);
public String register(){
log.info("获取页面数值pid:+pid+\t pname:"+pname);
return "reg";
}
缺点: 如果属性过多,该类中的方法相当多。属性跟模型中的属性不是重名,是一种资源的浪费;

3、在action中直接定义模型bean,然后对bean进行set,get,jsp页面上的属性"别名.属性名"来设置表单;
private UserBean userBean;
//省略set,get方法....
private Log log = LogFactory.getLog(HelloAction.class);
log.info("获取页面的参数pid:"+userBean);
return "reg";
}
缺点:jsp页面上的表单name属性,看着别扭;

4、在action中实现ModelDeriven接口,jsp页面传递过来的数据,表单域中如果没有指明"别名",属性就匹配ModelDriven
中的模型bean
public class UserTwoAtion implements ModelDriven<UserBean>{}
优点:form中的表单的name名称;
缺点:action中只能实现一个ModelDriven接口,就表示jsp页面只能向一个模型bean中注入数据;
如果在一个action类中相同时在两个或多个bean注入数据,请参考第三种获取值方式;

时间: 2024-08-19 13:39:44

控制层action获取jsp传递过来的参数有哪几种:的相关文章

获取网页URL地址及参数等的两种方法(js和C#)

转:获取网页URL地址及参数等的两种方法(js和C#) 一 js 先看一个示例 用javascript获取url网址信息 <script type="text/javascript"> document.write("location.host="+location.host+"<br>"); document.write("location.hostname="+location.hostname+&

Strut2 的 Action获取JSP 页面参数的方法

struts2 Action获取表单传值1.通过属性驱动式JSP:<form action="sys/login.action" method="post">      <input type="text" name="username">      <input type="submit" value="submit"></form> A

JS获取jsp页面中的参数

有如下代码: //java代码 [html] view plain copy <%String parm="hello word"%> [html] view plain copy //html代码 <input type="hidden" id="test" value="<%=parm%>"> //js代码 <script type="text/javascript&qu

Js获取url传递过来的参数

原理跟取cookie值一样的 function getParamer(paramer){ var url=window.location.href.split("?")[1];            /*获取url里"?"后面的值*/  if(url.indexOf("&")>0){                                      /*判断是否是一个参数还是多个参数*/     urlParamArry=u

springmvc后台控制层获取参数的方法

在SpringMVC后台控制层获取参数的方式主要有两种, 一种是request.getParameter("name"), 另外一种是用注解@RequestParam直接获取.这里主要讲这个注解 一.基本使用,获取提交的参数 后端代码: Java代码   @RequestMapping("testRequestParam") public String filesUpload(@RequestParam String inputStr, HttpServletReq

JSF通过超链接传递参数到控制层

JSF通过超链接传输数据到控制层可以分为三个步骤: 1.首先将数据加入到超链接中.通过<h:link>标签加入一个超链接,然后加入<f:param>标签加入参数.示例代码如下: 1 <h:link outcome="next.xhtml"> 2 跳转 3 <f:param name="id" value="2"/> 4 </h:link> 其中name和value会出现在url上,组成类

JSF在ui:include中传递参数到对应控制层

在JSF中使用ui:include方法可以引入一个页面到当前页面中,如果要向被包含的页面中传入参数,可以使用ui:param标签,这个标签类似于f:param,只不过一个用于页面,一个用于实际标签.示例代码如下: 1 <ui:include src="a.xhtml"> 2 <ui:param name="id" value="#{bean.id}" /> 3 </ui:include> 此时可以将一个属性名为

form中action属性后面?传递参数 获取不到

1 $p_id = $_REQUEST['p_id']; 2 3 echo "<h1>您将更新商品编号为<span>$p_id</span>的商品信息 <a href='listproduct.php'>查看所有</a></h1> 4 <form action='updateproduct.do.php?p_id=$p_id' method='get'> 5 商品名称:<input type='text'

SSH 框架controller向jsp传递List jsp中使用el表达式获取

mvc可以使用ModelAndViev传递数据选择跳转的视图 controller中的代码, 把一个模拟的表单studentListSimulate传给ModelAndView @RequestMapping("/detial") public Model showStudentDetial(Model mod) { ModelAndView mav = new ModelAndView(); mav.addObject("studentListSimulate",