Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Annotations on servlets  RSS feed

 
Ryan McClain
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it permitted or possible to use annotations on classic servlets?

e.g.:



I tried to visit my webapp with /appinfo appended after the context url but I get a 404 and I see no errors in the GlassFish4 log.
My project is using JSF 2.x with the viewservlet mapped on *.xhtml and it is using Spring Beans as well (using the Spring Context Loader), mapped to /rest/*.
Do I need to map something else?

I can only get this servlet working without annotations but only using the old web.xml way.

I don't know what I need to do to get my servlet working with annotations.



 
suraj august
Greenhorn
Posts: 24
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get this working by not using spring specific annotations and just servlet annotations.
Probably you have done the same using the old web.xml way.
so try this..

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

@WebServlet("/appinfo")
public class ApplicationInformation extends HttpServlet { ....
 
Ryan McClain
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that seems to work.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java EE 6 tutorial too has more examples for this http://docs.oracle.com/javaee/6/tutorial/doc/bnafu.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!