value stack是一些对象的几何,最后放到这个集合中的元素是:
Named Objects
原文: http://www.tutorialspoint.com/struts_2/struts_value_stack_ognl.htm
Named Objects
These objects include #application, #session, #request, #attr and #parameters and refer to the corresponding servlet scopes
以下代码治理了从表单到后台java,再到前台jsp的中文乱码。
所有jsp页面全用utf-8,然后用getBytes转换。实验了一下我写的乱码过滤监听器,不管用。本文后面源代码中带有这个监听器。
<%@ 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>Hello World</title>
</head>
<body>
<h1>Hello World From Struts2</h1>
<form action="hello">
<label for="name">请输入中文名字</label><br /> <input type="text" name="name" />
<input type="submit" value="Say Hello" />
</form>
</body>
</html>
<%@ 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>
Entered value :
<s:property value="name" />
<br />
<%
String temp = new String();
temp = (String) request.getAttribute("name");
temp = new String(temp.getBytes("iso-8859-1"), "utf-8");
out.println(temp);
out.println("<br/>");
%>
Value of key 1 :
<s:property value="key1" />
<br /> Value of key 2 :
<s:property value="key2" />
<br />
</body>
</html>
package com.tutorialspoint.struts2;
import java.util.*;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
private String name;
public String execute() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, Object> context = new HashMap<String, Object>();
context.put("key1", new String("这是键1"));
context.put("key2", new String("This is key2"));
stack.push(context);
System.out.println("Size of the valueStack: " + stack.size());
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
原文: http://www.tutorialspoint.com/struts_2/struts_value_stack_ognl.htm
源代码:http://pan.baidu.com/share/link?shareid=474582&uk=3878681452