
i have writteh the program lyk this ...still error 405 method not found is coming.please suggest me the solution.
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class Contextattribute extends HttpServlet
{
public void Service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("context created");
ServletContext ctx = getServletContext();
Integer count = (Integer)ctx.getAttribute("count");
if(count==null)
{count = new Integer(1);}
else
{count = new Integer(count.intValue()+1);}
ctx.setAttribute("count",count);
out.println(count.intValue());
}}

Hi Friend,
It seems that server is not getting the path of servlet.
Anyways, follow these steps:
Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Hello World</title></title>");
pw.println("<body>");
pw.println("<h1>Hello World</h1>");
pw.println("</body></html>");
}
}
2)Go to the webapps folder of your apache tomcat and create a web application folder but it should having an appropriate name like examples.
3)Create web.xml and classes folder inside the WEB_INF folder of web application folder.
4)Copy the servlet to the classes folder.
5)Edit the web.xml to include servlet?s name and url pattern.
6)Compile your servlet.
7)Run Tomcat server by clicking the startup.bat file. This is located inside the bin folder of apache tomcat.
8)Open the browser and type the following url:
http://localhost:8080/webapplicationfoldername/servletname
For more information, visit the following link:
Thanks

it got solved by removing braces at else ....
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.