如题,不知道原因何在.上网查了一些资料,但是80%都千篇一律的指向同一篇文章.可是我觉得文章并没有解决我的问题.希望这里的高手帮帮忙.但是千万别再引用那篇文章了.
问题出现原因很简单:
我就是想把一个html页面的东西打印出他的inputstream流出来
我的html页面源代码是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>测试页</title>
</head>
<body>
测试页<br>
<form id="formOne" name="formOne" method="post" action="test.action"
enctype="application/x-www-form-urlencoded">
名称:<input type="text" name="name"/><br>
<input type="submit" name="submitButton" value="提交"/>
</form>
</body>
</html>我的action里的代码是:
public class TestAction extends ActionSupport{ public String execute() throws IOException{ ActionContext act= ActionContext.getContext();
HttpServletRequest request= (HttpServletRequest)act.get(ServletActionContext. HTTP_REQUEST );

InputStream is = request.getInputStream();

//以http请求输入流建立一个BufferedReader对象
BufferedReader br = new BufferedReader(
new InputStreamReader(is));
String temp = "";
while((temp = br.readLine()) != null){
buffer = buffer + temp;
}
System.out.println("req:"+request.getParameterMap());//这句是好用的
System.out.println("buffer:"+buffer);                //这句什么也打不出来
return SUCCESS;
}
        private String buffer = "";
        .....
        .....
        get方法
        set方法等
}配置文件:可以也没什么特殊的,就是一个指向。请各位高手帮帮忙,指出问题所在。并且希望能针对我的这个问题,给我一个详细的解决办法。

解决方案 »

  1.   

    我也遇到了这个问题,开始的时候request的content-type也是设置成了application/x-www-form-urlencoded,在struts2中要求对content-type进行设置,结果这样设置是不行的,改成text/html,果然就可以在action中获取到输入流了。可以参考:http://waterdh.javaeye.com/blog/202608
      

  2.   

    非常感谢您的回答,但是我还是不太会设置,您看能不能参照我上面提问时的例子来给我设置下.
    是在<meta http-equiv="content-type" content="text/html"; charset="UTF-8"> 里设置 
    还是在<form id="formOne" name="formOne" method="post" action="test.action" enctype="application/x-www-form-urlencoded"> 里设置
    还是在action里对response进行设置.调用response.setContentType进行设置.