struts2 怎么在Action中获取 无参数名的数据?
struts2 怎么在Action中获取 无参数名的数据? --------------------编程问答-------------------- 什么 能详细说下吗贴代码看看 --------------------编程问答-------------------- 够经典的。
不过大体能够想象。
就是前端页面上有值,但是没有赋给名字。
比如<ingput type="text">这样无id无name无class的? --------------------编程问答-------------------- 前端:
function ajax_test(){
var xml = "xing=<name>zhangshan<name>"
$.ajax({ url: "test.action",
data: xml, type:"POST",
contentType:"text/xml",
dataType:"text",
processData:false,
success: function(data){
alert("Data Loaded: " + data);
}});
}
后台Struts2 Action怎么获得我前端提交的XML? --------------------编程问答-------------------- url啊,你不是写了test.action吗 --------------------编程问答-------------------- private String readXMLFromResQuestBody(HttpServletRequest request){
StringBuffer xml = new StringBuffer();
String line = null;
try{
BufferedReader reader = request.getReader();
while((line=reader.readLine())!=null){
xml.append(line);
}
}catch(Exception e){
System.out.println("Error reading XML:"+e.toString());
}
return xml.toString();
} --------------------编程问答-------------------- 对的 --------------------编程问答-------------------- 你写法就不对。。。应该是
data:{'xml':xml}
后台用属性xml接受。
补充:Java , Web 开发