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 ...
随机推荐
- QButton
Button.h #pragma once // QButton class QButton : public CButton { DECLARE_DYNAMIC(QButton) // Constr ...
- 【css】清除浮动(clearfix 和 clear)的用法
本文主要是讲解如何在 html 中使用 clearfix 和 clear,针对那些刚开始了解 css 的童鞋.关于 clearfix 和 clear 的样式在这里我就不写了,具体样式点击此处. 下面就 ...
- mysql reset password重置密码
安全模式启动 chown -R mysql.mysql /var/run/mysqld/ mysqld_safe --skip-grant-tables & 无密码root帐号登陆 mysql ...
- js关于函数和对象的概念
<script type="text/javascript"> function func1(fn){ if(typeof(fn)=="function&qu ...
- jspSmartUpload使用初步
jsp中使用SmartUpload上传文件 1.下载jspSmartUpload组件后,解压缩.把com目录复制到应用程序的WEB-INF\classes目录下. 2.尤其注意 (1)文件上传表单要添 ...
- JDBC的MySQL配置properties文件
参考: http://sgq0085.iteye.com/blog/1262469 e.g. 常用数据库URLDerby: jdbc:derby://localhost:1527/COREJAVA; ...
- Spring JDBC RowMapper接口示例
JdbcTemplate类使用org.springframework.jdbc.core.RowMapper <T>接口在每行的基础上映射ResultSet的行.该接口的实现执行将每行映射 ...
- CI框架 -- URI 路由
一般情况下,一个 URL 字符串和它对应的控制器中类和方法是一一对应的关系. URL 中的每一段通常遵循下面的规则:example.com/class/function/id/ 但是有时候,你可能想改 ...
- Java线程创建的两种方式
java多线程总结一:线程的两种创建方式及优劣比较 (一)---之创建线程的两种方式 java实现多线程的两种方法的比较
- C# 在EF中直接运行SQL命令
相信不少使用EF的同志们已经知道如何在EF中运行SQL命令了.我在这里简单总结下,希望对大家学习EF有所帮助! 在 EF第一个版本(.NET 3.5 SP1)中,我们只能通过将ObjectContex ...