struts开发<struts中的參数传递.三>
不说废话,直接上干货
1.通过set和get传递參数
添加username 和password两个属性并添加set和get方法
package fzl.user.struts.demo; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String list(){ System.out.println("list");
return "success";
}
public String input(){
System.out.println("input");
return "success";
} public String add(){ System.out.println("add");
return "success";
}}
在list使用EL表达式和struts标签调用
<pre name="code" class="html"><span style="font-size:18px;"><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
通过EL訪问
${username }-->${password }
<h1>------------------list -----------------</h1>
通过struts标签訪问
<s:property value="username"/>--><s:property value="password"/>
</body>
</html></span>
在浏览器输入http://localhost:9000/strustDemo1/User_list?username=fzl&password=123 传入參数
另外一种方法,通过Actioncontext完毕
<span style="font-size:18px;">package fzl.user.struts.demo; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String list(){
ActionContext.getContext().put("username", "flyou");
ActionContext.getContext().put("password", "553274238");
System.out.println("list");
return "success";
}
public String input(){
System.out.println("input");
return "success";
} public String add(){ System.out.println("add");
return "success";
}}</span>
list文件不用改动
第三种方法。通过servletAPI传值
<span style="font-size:18px;">package fzl.user.struts.demo; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String list(){
//ActionContext.getContext().put("username", "flyou");
//ActionContext.getContext().put("password", "553274238");
ServletActionContext.getRequest().setAttribute("username", "flyou");
ServletActionContext.getRequest().setAttribute("password", "553274238");
System.out.println("list");
return "success";
}
public String input(){
System.out.println("input");
return "success";
} public String add(){ System.out.println("add");
return "success";
}}</span>
list文件
<span style="font-size:18px;"><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
通过EL訪问
${username }-->${password }
<h1>------------------list -----------------</h1>
通过struts标签訪问
<span style="background-color: rgb(204, 0, 0);"><s:property value="#request.username"/>--><s:property value="#request.password"/></span>
</body>
</html></span>
获取的三种方式
1.通过seter和geter方法接受并传递
2.通过ActionContext.getContext().put("username", "flyou");传递參数
3.通过 ServletActionContext.getRequest.setAttribute("","")传值
struts开发<struts中的參数传递.三>的更多相关文章
- 再次学习javascript中的參数传递
javascript中的全部函数的參数传递都是依照值传递的,做了以下測试: function addTen(num){ num +=10; return num; } var count = ...
- java參数传递机制浅析
欢迎转载,转载请声明出处! ----------------------------------------- 前言: java语言中,參数的传递仅仅有一种机制.那就是值传递. 举例: 以下将通过几个 ...
- EBS OAF开发中实现參数式弹出窗体
EBS OAF开发中实现參数式弹出窗体 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 概览 參数式弹出窗体和嵌入式弹出窗体不一样,它拥有独立 ...
- struts开发<struts中的action详细配置. 二>
在eclipse中新建项目StrutsDemo1[struts的配置见]struts开发<在eclipse中配置struts. 一> 详细文件夹结构例如以下 第一种配置方法 新建UserA ...
- javascript获取当前url中的參数
javascript获取当前页面url中的參数能够使用location的search方法,获取到的是url中?后面的部分,比如http:localhost:8080/Manager/index.jsp ...
- 关于mybatis中,批量增删改查以及參数传递的问题
1.參数传递的问题 大多数情况下,我们都是利用map作为參数,而且大部分情况下都是仅仅有一个參数. 可是,我们也能够利用@param注解,来传入多个參数,此时,mybatis会自己主动将參数封装成ma ...
- c++參数传递
定义: 形參:指出如今Sub 和Function过程形參表中的变量名.数组名,该过程在被调用前.没有为它们分配内存.其作用是说明自变量的类型和形态以及在过程中的作用.形參能够是除定长字符串变量之外的合 ...
- FPGA编程基础(一)--參数传递与寄存器使用
一.參数映射 參数映射的功能就是实现參数化元件.所谓的"參数化元件"就是指元件的某些參数是可调的,通过调整这些參数从而可实现一类结构类似而功能不同的电路.在应用中.非常多电路都可採 ...
- C# 多线程參数传递
1.通过实体类来传递(能够传递多个參数与获取返回值),demo例如以下: 须要在线程中调用的函数: namespace ThreadParameterDemo { public class Funct ...
随机推荐
- 使用livereload实现自动刷新
livereload是一个web开发辅助工具,当我们修改完html.css和js的时候会自动刷新浏览器,解放码农的双手.这样在双屏切图.写js代码的时候会提高很多效率.livereload有很多版本, ...
- IDEA初始化配置
1.配置git 2.配置JDK[Configure-->Oroject Defaults-->Project Structure] 3.配置maven
- 《C++程序设计教程——给予Visual Studio 2008》读书笔记3章
CLR(Common Language Runtime,通用运行时),负责在执行时管理代码,提供内存管理和线程管理等核心服务,同时又确保代码的安全性和准确性.
- jquery 利用CSS 控制打印样式
一.添加打印样式 1. 为屏幕显示和打印分别准备一个css文件,如下所示: 用于屏幕显示的css: <link rel="stylesheet" href="cs ...
- [Intellij] Intellij IDEA 使用中遇见的问题
问题集锦 [IntelliJ IDEA14 + tomcat 设置热部署] 点击deployment查看Deploy at the server startup 中tomcat每次所运行的包是 xxx ...
- 关于Unity中GrabPass截屏的使用和Shader的组织优化
GrabPass截屏 可以用来截屏,截屏后把纹理传给下一个通道使用. 1:使用抓屏通道, GrabPass {} 或 GrabPass { “ 纹理名称”}; 使用GrabPass {}后,可以用_G ...
- 【Python】python3-list列表引用
print(names) #列出列表的内容 print(names[3]) #访问列表中第4个值 print(names[1:3]) #访问列表中从第2个到第3个的值 print(names[-1]) ...
- Java如何重置正则表达式的模式?
在Java编程中,如何重置正则表达式的模式? 以下示例演示如何使用Pattern类Pattern.compile()方法和Matcher类的m.find()方法来重置正则表达式的模式. package ...
- JDBC存储过程调用
在讨论JDBC Statement教程文章时,我们已经学习了如何在JDBC中使用存储过程. 本教程文章与该部分类似,但它将讲解演示有关JDBC SQL转义语法的其他信息. 就像Connection对象 ...
- How to suppress 'Maybe this is program method' warnings from ProGuard
11down votefavorite 2 I'm using ProGuard with my Android application and I'm running getting the war ...