This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes getResponse().setContentType( Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "getResponse().setContentType("text/html") returning nullpointer exception" Watch "getResponse().setContentType("text/html") returning nullpointer exception" New topic
Author

getResponse().setContentType("text/html") returning nullpointer exception

adrian bradley
Greenhorn

Joined: Mar 22, 2012
Posts: 3
I am having trouble understanding the http response in my servlet. I am outputting html to screen but its not working in IE9, i looked at posts that had similar issues and they seem to suggest that the response content type should be set to html for the browser to interpret as html. So I have tried adding the setcontent line just before I stream the html as per below



However it seems that the getResponse() is null and I am getting a null pointer exception.

My question is how can I get this to be not null, is there a way of creating a new instance of this? There is no get or post methods in the servlet and not sure what the best way of getting my html to execute in IE9, all other browsers work fine.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56204
    
  13

You'll need to post more context than just those two lines of code. Where do they exist? In what class? In what method?

HttpServlet doesn't even define a getRepsonse() method, the response is passed to the handler method. So what's defining getResponse()?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: getResponse().setContentType("text/html") returning nullpointer exception
 
Similar Threads
open file
servlet not displaying is downloading
doGet() and doPost()!!!
struts action and JSP chaining
setContentType