用struts2 action type=plaintext直接输出文本信息


1.作用:将response中的数据直接打印到当前页面指定的地方
2.配置:
<action name="test" class="testAction"method="test">
<result name="success" type="plainText">
<param name="charSet">UTF-8</param>
<param name="location">/test.jsp</param>
</result>
</action>
3.action中必须用response给客户端发送数据
ServletActionContext.getResponse().setContentType ("text/html;charset=utf-8");
PrintWriter out = ServletActionContext.getResponse().getWriter();
out.print("test");
out.flush();
out.close();
4.必须配置<param name="charSet">UTF-8</param>否则会出现乱码
5.必须配置<param name="location">/test.jsp</param>有可能会在服务器端报 java.lang.IllegalStateException错。

原文地址:https://www.cnblogs.com/123a/p/2662086.html