实例:现在jsp页面传递一个名为username的参数到action中
url: http://localhost:8080/StudentSystem/role_list.action?username=1321312
一、通过get set方法获取
在对应的action类中定义同名变量,并生成set get方法,那么参数将会自动获取值
String username;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
System.out.println(username);//结果为1321312
二、通过ServletActionContext获取//导入import org.apache.struts2.ServletActionContext;
HttpServletRequest reqeust= ServletActionContext.getRequest();
String username=reqeust.getParameter("username");//字符串
//url: http://localhost:8080/StudentSystem/role_list.action?username=1321312&username=34343
String[] username=reqeust.getParameterValues("username");//字符串数组
System.out.println(username);//结果为1321312
System.out.println(username[0]);//结果为1321312
三、通过ActionContext获取//导入import com.opensymphony.xwork2.ActionContext;
ActionContext context = ActionContext.getContext();
Map params = context.getParameters();
String[] username=(String[])params.get("username");
//ActionContext获取到一个对象如object或String[]
System.out.println(username[0]);//结果为1321312
分享到:
相关推荐
struts2中action如何获取jsp页面参数1.rar
struts2中action如何获取jsp页面参数1.pdf
struts2 中action 如何获取jsp 页面参数1.pdf
Struts2资源文件在jsp页面中显示乱码解决
jsp通过Ajax无刷新获取Action返回的模拟数据,然后通过struts2转化成json数据返回页面....这里面Map,List,对象等等,一些常用的操作都有。主要的代码在Action和 json.js里面。适合新手入门
下载后解压直接导入到Myeclipse中发布到tomcat后运行即可,源代码没有错误,已运行试过,三种方法转换的时候需要修改strut.xml中的Action
分别创建login.jsp和register.jsp两个页面实现登录和注册的输入,这两个页面提交给loginAction中的两个方法进行业务处理,如果成功发到success.jsp页面,否则转发到error.jsp页面。(源代码和实验报告)
通过jquery ajax 在struts2 action 和 jsp之间传递json
从jsp页面提交form表单后,在struts.xml中寻找匹配的action。在action中处理完业务后返回,在struts.xml中的result属性中转向到另外一个action。
6.7.2 Struts 2中常用的表达式语言特性 131 6.7.3 表达式语言的高级特性 135 6.8 小结 137 第7章 UI组件标签 139 7.1 为什么需要UI组件标签 139 7.2 标签、模板和主题 144 7.2.1 标签 146 7.2.2 模板 146 7.2.3 ...
struts2如何实现弹出action返回的错误信息
利用Struts 2标签创建ex3.jsp页面,此页面提交给tag.action,在structs.xml中配置这个action的转发视图为result.jsp在result.jsp页面中显示ex3.jsp页面控件的值。(源代码和实验报告)
NULL 博文链接:https://ewf-momo.iteye.com/blog/1708697
在本系列教程中 Web 工程的上下文路径都是 struts2 ,如果在 Web 根目录有一个 index.jsp 文件,则访问路径如下: http://localhost:8080/struts2/index.jsp 由于 MyEclipse6 目前并不支持 Struts2 ,所以我们需要到...
struts2 标签 Taglib (Struts2标签库)
详解Struts2中Action访问Servlet API的几种方法 在通常的web开发中Request和Response对象比较常见,但在Struts2框架中由于Action能与JSP页面进行数据交互,所以通常都不会用到这两个对象。如果想在Struts2程序中用到...
用Struts2新建一个应用的方法步骤用Struts2新建一个应用的方法步骤: 1.首先新建一个Web Project。File——new——Web Project,在Project Name中输入一个合法的名字。例如:struts2 2. 单击采单Window——...