Im working on Struts2 project, In action class im passing string to jsp page. I want to display that string content as xml in jsp page.
jsp page : response.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:property value="sampleStr" />
Action class : ResponseAction
public class ResponseAction extends ActionSupport {
private static final long serialVersionUID = 1L;
public String sampleStr;
public String execute() throws IOException {
String responseStr = readStringFile();
setSampleStr(responseStr);
return SUCCESS;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public String readStringFile() throws IOException{
String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"+
"<response>"+ "$$" +
"</response>";
InputStream inputStream = XmlFormatter.class.getResourceAsStream("/sample.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-16")));
String s = "";
List list = new ArrayList();
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
}
for (Object s1: list) {
s= s + s1;
}
xmlStr = xmlStr.replace("$$", s);
return xmlStr;
}
public String getSampleStr() {
return sampleStr;
}
public void setSampleStr(String sampleStr) {
this.sampleStr = sampleStr;
}
}
Struts.xml :
<package name="default" namespace="/" extends="struts-default">
<action name="PEConsolidation" class="com.metlife.ibit.pe.web.controller.actions.ResponseAction">
<interceptor-ref name="defaultStack" />
<result name="success">/WEB-INF/jsps/response.jsp</result>
</action>
</package>
When i looks response.jsp, it display return string as text. please anyone help to display as xml content?