aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Servlet Annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Servlet Annotations" Watch "Servlet Annotations" New topic
Author

Servlet Annotations

Prathik Ashok
Greenhorn

Joined: Mar 27, 2012
Posts: 12
hello


I've been trying to learn about servlets i am basically a begginer and I basically have a problem while i declare @WebServlet annotation my eclipse says it cannot be resolved into a type when i did some research on it i found this link

http://www.eclipse.org/jdt/apt/introToAPT.html

i followed all the steps in that but still i get the error message what should i do???

This is the code for the servlet as you can see i'm stuck here

package org.prathik.sample;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class SimpleServlet
*/
public class SimpleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@WebServlet(description = "A Simple Servlet" , urlPatterns ={"/SimpleServletPath"})
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.print("sample Web Servlet");
PrintWriter writer = response.getWriter();
writer.print("Hello :");
}

}


I am trying to learn from scratch as i basically new to servlets so could some one guide me in the right direction

Thanks

Prathik
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Does the Servlets container support Servlets 3.0?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prathik Ashok
Greenhorn

Joined: Mar 27, 2012
Posts: 12
no cause in my web.xml file it says version 2.5 when i try to change it says 3.0 is not supported

here's the code of my web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ServletExample12</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description>A simple Servlet</description>
<display-name>SimpleServlet</display-name>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>org.prathik.sample.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServletPath</url-pattern>
</servlet-mapping>
</web-app>

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Well, then why should you be surprised when Servlet 3.0 annotations don't work with a Servlets 2.5 container?
Prathik Ashok
Greenhorn

Joined: Mar 27, 2012
Posts: 12
ohhh ok I just found this link http://search.maven.org/#artifactdetails|javax.servlet|javax.servlet-api|3.0.1|jar

which one should i download??

i am new to coding so please help me out here

and thanks for your reply
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Having the API jar is not going to help you without a container that supports it. Why not just download Tomcat 7 and be done with it?
Prathik Ashok
Greenhorn

Joined: Mar 27, 2012
Posts: 12
Alright i got Apache tomcat version 7.0 and i got it running and added all the libraries when i create a new dynamic project and check the version in web.xml file it still shows version is 2.5
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

I'm moving this to the IDEs forum as the Servlets forum is not the place to discuss how to use an IDE.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

What IDE are you using? The IDE should ask you which servlet version you want to support, but exactly how to specify that version varies depending on the IDE.

Besides, why don't you simply replace the existing version info with the correct one? After all, the web.xml file is just a text file. See this: http://dominikdorn.com/2010/03/web-xml-web-fragment-xml-2-3-2-4-2-5-3-0/


JBoss In Action
Prathik Ashok
Greenhorn

Joined: Mar 27, 2012
Posts: 12
thanks that worked now my IDE recognizes servlet annotations

thank you very much once again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Annotations