我也遇到了同样的问题,但是现在解决了,如下:ExampleTextAction.javapackage sample;public class ExampleTextAction { public String preview() throws Exception { return "textreport"; } } struts.xml<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="text-example" namespace="/sample-text" extends="struts-default"> <action name="test" class="sample.ExampleTextAction" method="preview"> <result name="textreport" type="plainText"> <param name="location">/test.jsp</param> </result> </action> </package> </struts>说明: struts.xml file should have a result name as textreport with type as plainText and having location param pointing to the actual text file, whose content is to be shown on screen as plain text.
<action name="EA0001Code" method="doCode"
class="ea0001Action">
<result type="plainText">
<param name="location">
/WEB-INF/jsp/debug/expres/aognl/EA0001.jsp
</param>
<param name="charSet">UTF-8</param>
</result>
</action>
<action name="plaintext">
<result type="plainText">
<param name="location">/index.jsp</param>
<param name="charSet">UTF-8</param>
</result>
</action>
//index.jsp------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<%=new Date() %><br>
</body>
</html>
显示:什么都没有
pageEncoding="utf-8" import="java.util.*"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<%=new Date() %><br>
</body>
</html>
public String preview() throws Exception {
return "textreport";
}
}
struts.xml<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="text-example" namespace="/sample-text"
extends="struts-default">
<action name="test" class="sample.ExampleTextAction"
method="preview">
<result name="textreport" type="plainText">
<param name="location">/test.jsp</param>
</result>
</action>
</package>
</struts>说明:
struts.xml file should have a result name as textreport with
type as plainText and having location param pointing to the
actual text file, whose content is to be shown on screen as plain
text.
其结果,是一样的!