ajax发XML给Struts,Struts收不到??
在struts的action应用
request.setCharacterEncoding( "UTF-8 ");
BufferedReader reader = request.getReader();
boolean is = false;
while ((line = reader.readLine()) != null) {
is = true;
}
结果System.out.println(is);打印结果为false,不知其中缘由,传说request.getReader();方法只能调用一次
但是呢,一个简单的例子就能成功,如下:
Servlet> > >
package servlet;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import
java.io.IOException;
import java.io.PrintWriter;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilderFactory;
import
javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import
org.xml.sax.SAXException;
public class TestServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public TestServlet() {
super();
}
/**
* Destruction of the servlet. <br/>
*/
public void destroy() {
super.destroy(); // Just puts "destroy " string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding( "UTF-8 ");
System.out.println( "Ajax Start...... ");
String name = "no ";
String password = "00 ";
/**
* 读取xml格式的参数
*/
StringBuffer readXml = new StringBuffer();
String line = null;
boolean is = false;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
readXml.append(line);
is = true;
} <