• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert jsp output from html to xml  RSS feed

 
Kevin Wong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to spell the method correctly. See the JavaDoc to find your error.
 
Kevin Wong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Opps thank you for your help!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!