PlainText Result is a result type. It Sends out the content to the user as a plain text. It can be used when you wish to send out raw content on a HTML or JSP file.
To use the PlainText Result you need to to do the following mapping with the struts.xml file
<action name="rawData" > <result type="plainText"> <param name="location">/jsp/helloPage.jsp</param> <param name="charSet">UTF-8</param> </result> </action>
Here location is the location of the HTML or JSP file. And charSet is type of the character set you will use.ADS_TO_REPLACE_1
An example of Plain Text Result is given below.
SampleInterfaceImp.java
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Index Page</TITLE> </HEAD> <BODY bgcolor="lightblue"><br clear="all"/><br clear="all"/> <h2>Index</h2> <font color="green" face="modern" size="4"> <ul> <li>View the <a href="rawData.action">JSP</a> File In Plain Text</li><br clear="all"/> <li>View the <a href="textData.action">Text</a> File In Plain Text</li> </ul> </font> </BODY> </HTML>
testJSP.jspADS_TO_REPLACE_2
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Plain Text Example</title> </head> <body bgcolor="lightblue"> <font size="6" face="modern">This is Plain Text Demo</font> </body> </html>
testText.txt
Hi This is test raw file you are looking on the Browser ....................
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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="roseindia" extends="struts-default"> <action name="rawData" > <result type="plainText"> <param name="location">/jsp/testJSP.jsp</param> <param name="charSet">UTF-8</param> </result> </action> <action name="textData" > <result type="plainText"> <param name="location">/jsp/testText.txt</param> <param name="charSet">UTF-8</param> </result> </action> </package> </struts>
|
Download this example codeADS_TO_REPLACE_3
Advertisements
Ads
Ads