Beruflich Dokumente
Kultur Dokumente
Servlets are the programming concepts of J2EE , and it used for developing the web
applications .
The Servlets are server side language , so it is required to install the web server software
for it.
The webserver is the software which is required for performing the virtual client server
environment, some of the commonly used webserver softwares are ,
1. JBOSS
2. Java Web Server
3. Jakarta Tomcat
In order to run the servlets , we are required to set some environment variables.
1. JAVA_HOME
This environment variable is used for setting the home directory where the java
development kit software is installed.
3. CATALINA_HOME
This environment variable is used for setting the path for the home directory for the
tomcat directory.
Handling Requests
In contrast, an HTTP servlet usually does not override the service() method.
Instead, it overrides doGet() to handle GET requests and doPost() to handle POST
requests. An HTTP servlet can override either or both of these methods, depending on
the type of requests it needs to handle. The service() method of HttpServlet
handles the setup and dispatching to all the doXXX() methods, which is why it
usually should not be overridden
getParameter
If the parameter data was sent in the request body, such as occurs with an HTTP
POST request, then reading the body directly via getInputStream() or
getReader() can interfere with the execution of this method.
getParameterNames
getParameterValues
Returns an array of String objects containing all of the values the given request
parameter has, or null if the parameter does not exist. If the parameter has a
single value, the array has a length of 1.
getParameterMap
1. url-pattern
It specifies the type of urls for which, the servlet given in servlet-name should
be called.
2. servlet-name
1. Create the folder with name sdemos in the directory F:\Tomcat 6.0\webapps
3. Now create the folder classes and copy the web.xml file in the folder F:\Tomcat
6.0\webapps\sdemos\WEB-INF
4. Create you file HelloWorld.java in the folder class and compile it.
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>SamplesDemo</servlet-name>
<servlet-class>SamplesDemo</servlet-class>
</servlet>
<servlet>
<servlet-name>DateExample</servlet-name>
<servlet-class>DateExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SamplesDemo</servlet-name>
<url-pattern>/SamplesDemo</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DateExample</servlet-name>
<url-pattern>/DateExample</url-pattern>
</servlet-mapping>
</web-app>