PlainText Result Example
Posted on: January 19, 2011 at 12:00 AM
In this tutorial you will learn that how to send out a raw content to the user

PlainText Result Example

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>


Here location is the location of the HTML or JSP file. And charSet is type of the character set you will use.

An example of Plain Text Result is given below.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE>Index Page</TITLE>
<BODY bgcolor="lightblue"><br clear="all"/><br clear="all"/>
<font color="green" face="modern" size="4">
<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>



<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Plain Text Example</title>

<body bgcolor="lightblue">
<font size="6" face="modern">This is Plain Text Demo</font>


Hi This is test raw file you are looking on the Browser ....................


<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


<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>


<action name="textData" >

<result type="plainText">
<param name="location">/jsp/testText.txt</param>
<param name="charSet">UTF-8</param>




When you run this application it will display message as shown below:


Download this example code

Related Tags for PlainText Result Example:



Advertisement null