Wednesday, August 12, 2009

How do I pass arguments to the Servlets?

Arguments to the servlets can be passed at two levels.

When a client is invoking the servlet, the client can pass the arguments as part of a URL in form of name/value pairs in the query string portion of the URL. If a tag is used in the html language to invoke the servlet, the arguments can be passed through the param name construct:




The server administrator/web-master can pass arguments to the servlet at loading/intialization time by specifying the arguments as part of the server configuration. For Tomcat and JSWDK, edit the conf/web.xml file.

The required argument (parameter1 in this example ) can be retrieved this way, getServletContext().getAttribute( "paramater1")

No comments:

Post a Comment