How to convert jsp output from html to xml
843840Mar 28 2009 — edited Mar 30 2009Hi All
I have not done java web programming for 1 year, actually still very junior at it.
Trying to remember how to program jsp's again.
I have a simple jsp to write, that takes simple user text input and then want the jsp to return xml back to browser.
I have a method I would like to use called setContentType but have not been able to use it in the jsp.
I have listed the code below, when I run the jsp from tomcat servlet container, it throws up an error
"The method setContextType(String) is undefined for the type HttpServletResponse"
Not sure why it should throw up the error as setContextType method is from the ServletResponse that is a
super class of HttpServletResponse.
Please help as not sure what the issue is!
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>My REST Service</title>
</head>
<body>
<%
String req = request.getParameter("studentNumber");
if ( req == null ) {
response.setContextType("text/html");
out.println("<FORM METHOD=POST ACTION=\"studentService.jsp\">");
out.println("Please enter student number:");
out.println("<INPUT TYPE=TEXT NAME=studentNumber SIZE=20><P><INPUT TYPE=SUBMIT>");
out.println("</FORM>");
} else {
response.setContextType("text/xml");
response.setHeader("Cache-Control","no-cache");
out.println("The result is 9003888");
}
%>
</body>
</html>
Thanks in Advance