• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Annotations

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the Servlets container support Servlets 3.0?
 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, then why should you be surprised when Servlet 3.0 annotations don't work with a Servlets 2.5 container?
 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to the IDEs forum as the Servlets forum is not the place to discuss how to use an IDE.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/
 
Prathik Ashok
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks that worked now my IDE recognizes servlet annotations

thank you very much once again
reply
    Bookmark Topic Watch Topic
  • New Topic