2

The title says it all. I need the getStatus() function on a HttpServletResponse instance. The API says it exists. Netbeans shows that request as an error, saying 'cannot find symbol'. When I disassemble the javaee.jar file, the HttpServletResponse class does not show the getStatus() function nor any of the other get()s I need.

I suppose I somehow have the wrong .jar file, although I do know it's from J2EE 6. If this is the case, where can I get the correct jar file ( and which one ) without downloading the whole J2EE distro?

I've also found the javaee-api-6.0.jar file. Unlike the j2ee.jar file, it does have the functions I need defined. And, like the j2ee.jar, all of it's functions are abstract ... and the answer is coming to me ... since the functions are abstract, they can't run, they only exist to compile against, right? I'm coding this to run in Tomcat, so there's no way to properly test this just sitting in my IDE, is there? It needs to sit in Tomcat and run in Tomcat. So there must be jar file in Tomcat that can run this. Hmmm.

Yes?

Thanks.

joe7pak
  • 300
  • 1
  • 4
  • 16
  • You need to add the Tomcat server to your Netbeans. This will allow Netbeans to access the web server libraries that tomcat contains. – abalos Sep 23 '14 at 15:42
  • Can you upgrade to Tomcat7? Since Servlet 3.0, there's a HttpServletResponse#getStatus(). Otherwise the call is hidden and you need a wrapper to access it (using a filter) – Victor Sep 23 '14 at 16:17
  • @Victor - I am using Tomcat7 ( 7.0.50 ). I'm afraid I'm unfamiliar with "needing a wrapper" and "using a filter". Ok, I'm looking at your answer below... – joe7pak Sep 23 '14 at 16:56
  • @abalos - I have gone ahead and done what you suggested. While it does not solve my immediate problem, I believe it did need to be done. Thx. – joe7pak Sep 23 '14 at 17:16

1 Answers1

0

See this answer to a similar question: https://stackoverflow.com/a/1302165/3046834

The best practice is to code always using the API jar and not a Server specific jar. Using a filter and the wrapper exposed in the answer above, you will be able to access the status code.

Community
  • 1
  • 1
Victor
  • 2,450
  • 2
  • 23
  • 54
  • I am using TC 7. I've looked at the page, and see an interesting comment ... >>> So, if there's room for upgrading, upgrade to Servlet 3.0 (Tomcat 7, Glassfish 3, JBoss AS 6, etc) and you don't need a wrapper. chain.doFilter(request, response); int status = ((HttpServletResponse) response).getStatus(); – joe7pak Sep 23 '14 at 19:39
  • So, here's this from the page you referenced I'm using Tomcat7 ... I'm not quite sure where I get these references from or exactly where to place this code ... could you elaborate? chain.doFilter(request, response); int status = ((HttpServletResponse) response).getStatus(); Thx – joe7pak Sep 23 '14 at 20:15
  • OK. These examples are both referencing a filter execution. That is, you have to define a filter that "captures" the Servlet request execution. Once you get the response, inside the filter execution, you are able to examine the content of the HTTPServletResponse. In order to define a filter you have several methods, either annotations or in the web.xml – Victor Sep 23 '14 at 20:43
  • In order to define a filter you will have to implement a class that implements the Filter interface and a couple of tags in the web.xml. See this [link](http://www.journaldev.com/1933/java-servlet-filter-example-tutorial) for more info. Inside the filter.doFilter() capture the status from the HttpServletResponse. – Victor Sep 23 '14 at 20:45