在Struts的Action中遍历Attribute没有想要的属性名,但是如果精确的用getAttribute(key)就能获取,不知道怎么回事.
private String arg;
private String htmlId;
@Override
public String execute()
{
HttpServletRequest req = ServletActionContext.getRequest();
// Attribute
Enumeration attrNames = req.getAttributeNames();
for (int i=0;attrNames.hasMoreElements();i++)
{
Object obj = attrNames.nextElement();
System.out.println((String)obj);
}
String str1 = (String) req.getAttribute("arg");
System.out.println("Attribute 1==== " + str1);
String str2 = (String) req.getAttribute("htmlId");
System.out.println("Attribute 2==== " + str2);
return "ok";
}
用ajax发送的json格式的数据
xhr.setRequestHeader("Content-type", "application/json");
str1={"arg":"ab","htmlId":"ac"};
xhr.send(JSON.stringify(str1));
结果是
struts.actionMapping
__cleanup_recursion_counter
struts.valueStack
Attribute 1==== ab
Attribute 2==== ac
奇了怪了.