Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet context attribute
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Aayshi Mehrotra
context attribute
2 Answer(s)      3 years and 11 months ago
Posted in : JSP-Servlet


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());
}}

Advertisement
View Answers

January 27, 2011 at 1:55 PM


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.

Hello HelloWorld Hello /HelloWorld

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:

Servlet Tutorials

Thanks



January 27, 2011 at 3:28 PM


it got solved by removing braces at else ....



Related Tutorials/Questions & Answers:
context attribute
context attribute  i have writteh the program lyk this ...still error 405 method not found is coming.please suggest me the solution. import... { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("context
context
context  what is context in general in java ?   An association between a name and an object is called a binding, and a set of such bindings is called a context
Advertisements
Servlet Context
Servlet Context  Defined Servlet Context
Context binding
Context binding  What is meant by Context binding?   A binding context is an object that holds data that you can reference from your... context that refers to the nested view model data.   Thanks:-) public
What is Application Context?
What is Application Context?  Hello, What is Application Context? Thanks
Application context problem code
( WebApplicationContext.ROOT WEB APPLICATION CONTEXT ATTRIBUTE, applicationContext...Application context problem code   now i am posting my code here . i... FileSystemXmlApplicationContext context = null; protected SessionFactory sessionFactory=null
application context file problem
application context file problem  how to configure junit application context file with struts........? it is not finding sessionfactory method
Message Context in AXIS
Message Context in AXIS  Is there any method in Axis classes to het the size of IN and OUT Message Conetext
Servlet Context
Servlet Context In this section we will read about the SevletContext... by providing the value in web.xml file using the <context-param></context... the attribute from web.xml file. ServletContext object can allow for the inter
context menu overlapped in IE8
context menu overlapped in IE8  I developed a contex menu in XHTML while opening it is overlapped in border of IE8 browser. even i have tried change the zaxis in css. I am using like below
Error in context path
Error in context path   I Tried a Struts2 Login application having... = request.getContextPath(); System.out.println("Context Path " + contextPath... ... undeploy?path=/strutsDemo OK - Undeployed application at context path /strutsDemo
Add context path to URL for outputLink
Add context path to URL for outputLink  How to add context path to URL for outputLink
jsf attribute
jsf attribute  What is the different between value and binding attribute of jsf
Context attributes in Servlet
Context attribute is used by all servlets and jsp in a context or web application... Context attributes in Servlet       In this section you will study about the use of  Context
Spring Context - Writing Application Context
Spring Context - Writing Application Context  ... by defining the Application context definition file (applicationContext-hibernate.xml). This file is used by context loader servlet to initialize the Spring
Java Thread Context
Thread Context       The Thread Context is required by the current thread from the group... for the development of the thread pools Every Thread required a context
multivalued attribute
multivalued attribute  I have a author as multivalued attribute and i have inserted values for it in database but now how to insert values in the database through form .I have written query as shown below and iam getting error
multivalued attribute?
multivalued attribute?  I have a problem in editing the database through form because of multivalued attribute it is creating the error and also how to write code for displaying the data when there is multivalued attribute
multivalued attribute?
multivalued attribute?  I have a problem in editing the database through form because of multivalued attribute it is creating the error and also how to write code for displaying the data when there is multivalued attribute
Use Log in Servlet Context
Use Log in Servlet Context       This section illustrates you how to use log in Servlet Context. We are providing you an example. In the given example, an object of Servlet Context is defined
Spring Context Loader Servlet
Spring Context Loader Servlet       In this section we will learn about Spring's Context... in the web.xml file to load the Spring Context. Spring ContextLoaderServlet
What are difference between Bean Factory and Application Context ?
What are difference between Bean Factory and Application Context ?  Hi, What are difference between Bean Factory and Application Context
java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractRefreshableConfigApplicationContext
java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractRefreshableConfigApplicationContext  Hi, How to solve java.lang.NoClassDefFoundError: org/springframework/context/support
Getting Context Parameter Names
Getting Context Parameters NamesGetting Context Parameter Names In this section, you will learn how to get  the context parameters which we have given... with the servlet container. There is only one Servlet Context for the entire web
MySQL Attribute
MySQL Attribute This example illustrates how to use the COLLATE attribute in MySQL. In this example we use the COLLATE attribute to define the attribute... and collation for the column. Query CREATE TABLE atttribute (attribute_name CHAR
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
Language Attribute In Page Directive
Language Attribute In Page Directive  How use language attribute in page directive
Quotes around attribute values.
Quotes around attribute values.  Should I put quotes around attribute values
JSF Rendered Attribute
JSF Rendered Attribute  i need the example for jsf with rendered attribute
Use of immediate attribute
Use of immediate attribute  What is the use of immediate attribute
value and binding attribute
value and binding attribute  What is the difference between value and binding attribute of jsf tag
 

 

 

DMCA.com