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 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());
}}
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
jsf attribute
jsf attribute  What is the different between value and binding attribute of jsf
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
Quotes around attribute values.
Quotes around attribute values.  Should I put quotes around attribute values
Language Attribute In Page Directive
Language Attribute In Page Directive  How use language attribute in page directive
What is attribute oriented programming?
What is attribute oriented programming?  Hi, What is attribute oriented programming? Thanks
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
Use of immediate attribute
Use of immediate attribute  What is the use of immediate attribute
JSF Rendered Attribute
JSF Rendered Attribute  i need the example for jsf with rendered attribute
value and binding attribute
value and binding attribute  What is the difference between value and binding attribute in jsf
value and binding attribute
value and binding attribute  What is the difference between value and binding attribute of jsf tag
Language Attribute In Page Directive
Language Attribute In Page Directive  How use language attribute in page directive ?   This attribute is used to denote the language used... of language attribute for page directive is :ADS_TO_REPLACE_1 <%@ page language
Servlet Context
Servlet Context  Defined Servlet Context
JavaScript Defer Attribute
JavaScript Defer Attribute  defer attribute in javascript   Hi Friend, The defer attribute gives a hint to the browser that the script does not create any content so the browser can optionally defer interpreting
contentType attribute in the page directive
contentType attribute in the page directive  How use contentType attribute in the page directive ?   contentType attribute is used to set the mime type and character set of the JSP. The user can make use of any MIME
Import attribute of page directive
Import attribute of page directive   How use import attribute of page directive ?   The import attribute is used to import all the classes in a java package into the current JSP page. If there are many Java packages
errorPage attribute in the page directive
errorPage attribute in the page directive  How use errorPage attribute in the page directive ?   If the programmer wants to place errors... in this attribute as errorPage. Syntax :ADS_TO_REPLACE_1 <%@ page errorPage="relativeURL
Buffer attribute in the page directive
Buffer attribute in the page directive  How use buffer attribute in the page directive?   The buffer size in kilobytes used by the out object to handle output sent from the compiled JSP page to the client Web browser
AutoFlush attribute in the page directive
AutoFlush attribute in the page directive  How use autoFlush attribute in the page directive?   Whether the buffered output should be flushed automatically when the buffer is full. If set to true (the default value
isThreadSafe attribute in the page directive
isThreadSafe attribute in the page directive  How use autoFlush attribute in the page directive?   autoFlush means it will not clear. it send to the desitation.   Whether thread safety is implemented
isErrorPage attribute in the page directive
isErrorPage attribute in the page directive  How use isErrorPage attribute in the page directive ?   isErrorPage attribute is used...; isErrorPage attribute is used to specify whether or not a JSP page displays
retrieve multiple attribute values
retrieve multiple attribute values  Hello All Am a beginner. Would like some help with this. The following is part of my XML file: <process... like is to retrieve both the attribute values of process:Output during execution
retrieve multiple attribute values
XML retrieve multiple attribute values  Hello All Am a beginner. Would like some help with this. The following is part of my XML file: <...; What I would like is to retrieve both the attribute values of process
retrieve multiple attribute values
retrieve multiple attribute values  Hello All Am a beginner. Would like some help with this. The following is part of my XML file: <process... like is to retrieve both the attribute values of process:Output during execution
How to use contentType Attribute in JSP?
How to use contentType Attribute in JSP?  Hi, I am learning JSP and now trying to use the contentType Attribute in JSP. tell me how to use the contentType Attribute in JSP? Thanks
Extends Attribute of page Directive
Extends Attribute of page Directive   How use language extends in page directive ?   This is used to signify the fully qualified name of the Super class of the Java class used by the JSP engine for the translated
ModuleNotFoundError: No module named 'attribute-mapping'
ModuleNotFoundError: No module named 'attribute-mapping'  Hi, My... named 'attribute-mapping' How to remove the ModuleNotFoundError: No module named 'attribute-mapping' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'attribute_wrapper'
ModuleNotFoundError: No module named 'attribute_wrapper'  Hi, My... named 'attribute_wrapper' How to remove the ModuleNotFoundError: No module named 'attribute_wrapper' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'attribute-dict'
ModuleNotFoundError: No module named 'attribute-dict'  Hi, My... named 'attribute-dict' How to remove the ModuleNotFoundError: No module named 'attribute-dict' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'attribute_wrapper'
ModuleNotFoundError: No module named 'attribute_wrapper'  Hi, My... named 'attribute_wrapper' How to remove the ModuleNotFoundError: No module named 'attribute_wrapper' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'attribute_tree'
ModuleNotFoundError: No module named 'attribute_tree'  Hi, My... named 'attribute_tree' How to remove the ModuleNotFoundError: No module named 'attribute_tree' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'attribute_wrapper'
ModuleNotFoundError: No module named 'attribute_wrapper'  Hi, My... named 'attribute_wrapper' How to remove the ModuleNotFoundError: No module named 'attribute_wrapper' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'attribute-mapping'
ModuleNotFoundError: No module named 'attribute-mapping'  Hi, My... named 'attribute-mapping' How to remove the ModuleNotFoundError: No module named 'attribute-mapping' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'attribute_tree'
ModuleNotFoundError: No module named 'attribute_tree'  Hi, My... named 'attribute_tree' How to remove the ModuleNotFoundError: No module named 'attribute_tree' error? Thanks   Hi, In your python
Version of nanning>nanning-attribute dependency
List of Version of nanning>nanning-attribute dependency
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
Page Directive attribute - language
Page Directive attribute - language This section contains description of language attribute of page Directive. language Attribute : The language attribute is one of attribute of page directive. Its functionality to specify
attribute in action tag - Java Beginners
attribute in action tag  I'm just a beginner to struts. The name tag(name="bookListForm") is used to define the form used with the action class. But i`m not clear about the attribute tag(attribute
<html:option > with "selected" attribute - Struts
with "selected" attribute  how to display formbean object with "selected" attribute in . please help me
Page Directive attribute - isThreadSafe
Page Directive attribute - isThreadSafe This tutorial  contains description of isThreadSafe attribute of page Directive. isThreadSafe Attribute : isThreadSafe attribute is one of attribute of page directives. It is used
Page Directive attribute - pageEncoding
Page Directive attribute - pageEncoding This tutorial contains description of pageEncoding attribute of page Directive. pageEncoding Attribute : Page directive provides pageEncoding attribute to specify the language that the page uses
The info Attribute of page Directive In JSP
The info Attribute of page Directive In JSP  ... about the info attribute of the page directive in JSP. This attribute simply... Servlet.getServletInfo() method. The value of the attribute will be a text string. Here
Page Directive attribute - buffer
Page Directive attribute - buffer This section contains description of buffer attribute of page Directive. buffer Attribute : This attribute is used for specifying the buffer size for the output stream. Buffer size is specified
Page Directive attribute - extends
Page Directive attribute - extends This tutorial  contains description of extends attribute of page Directive. extends Attribute : This attribute specifies the super class of the JSP page's implementation servlet. It allows
Page Directive attribute - info
Page Directive attribute - info This tutorial  contains description of info attribute of page Directive. info Attribute : info attribute of page... of the attribute will be a text String. This feature is useful where a huge number of server
What is Application Context?
What is Application Context?  Hello, What is Application Context? Thanks
Page Directive attribute - isErrorPage
Page Directive attribute - isErrorPage This tutorial  contains description of isErrorPage attribute of page Directive. isErrorPage Attribute : This attribute of page directives sets the boolean value either true or false

Ads