6

I have create following java file,compile it and got .class file.

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>"); out.println("<head>"); out.println("<title>First Example</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello World!</h1>"); out.println("</body>"); out.println("</html>"); } } 

Now i created directory abc/WEB-INF/classes under apache-tomcat-6.0.32/webapps directory so my classFile Path is : apache-tomcat-6.0.32/webapps/abc/WEB-INF/classes/HelloWorld.class and trying to access http://localhost:8080/abc/WEB-INF/classes/HelloWorld, but getting error "The requested resource (/abc/HelloWorld) is not available"

Where i am going wrong? or should i have to specify other configuration?

1
  • 1
    pdf.coreservlets.com Try giving this book a read. You wont be able to access anything inside your WEB-INF directly. Commented Aug 4, 2011 at 12:07

2 Answers 2

25

you must define your servlet in the web.xml

<servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>yourpackage.HelloWorld</servlet-class> </servlet> 

and then define the mapping from URL to servlet

<servlet-mapping> <servlet-name>HelloWorld</servlet-name> <url-pattern>/HelloWorld</url-pattern> </servlet-mapping> 

and finally type the URL as: http://localhost:8080/abc/HelloWorld

Sign up to request clarification or add additional context in comments.

Comments

2

You need to configure your servlet in your web.xml.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.