Let us start Servlet first programm,
First of all,
STEP 1: Create folder in webapps which is exising in Apache Tomcat folder
Folder name as Hello
STEP 2: Now in Hello folder you have to create index.html file and code as Below
<html>
<head>
<title>Wel come</title>
</head>
<body >
<a href="Hello">Click here</a>
</body>
</html>
I hope you have created it.
STEP 3: After that create new folder in Hello foder which name is WEB-INF
STEP 4: Now create one file which name is web.xml and make sure it's extenstion is .xml and coded
with below code
<web-app>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
this file used to mapping between servlet to your servlet file
STEP 5: Now create one folder in WEB-INF foder which name is classes
STEP 6: In classes folder create your servlet file which name is Hello.java
complie it
as per below code
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>Hello World!</body></html>");
}
}
STEP 7:After complation of your programm yu have to open Apche server in
browser
like ,
http://localhost:8080/
click on manager apps
and then clcik on list of Application
After that you found your example name as Hello
Click on Hello link
Enjoy........
DOWNLOAD EXAMPLE
Downlod files and Extract in webapps folder
First of all,
STEP 1: Create folder in webapps which is exising in Apache Tomcat folder
Folder name as Hello
STEP 2: Now in Hello folder you have to create index.html file and code as Below
<html>
<head>
<title>Wel come</title>
</head>
<body >
<a href="Hello">Click here</a>
</body>
</html>
I hope you have created it.
STEP 3: After that create new folder in Hello foder which name is WEB-INF
STEP 4: Now create one file which name is web.xml and make sure it's extenstion is .xml and coded
with below code
<web-app>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
</web-app>
this file used to mapping between servlet to your servlet file
STEP 5: Now create one folder in WEB-INF foder which name is classes
STEP 6: In classes folder create your servlet file which name is Hello.java
complie it
as per below code
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>Hello World!</body></html>");
}
}
STEP 7:After complation of your programm yu have to open Apche server in
browser
like ,
http://localhost:8080/
click on manager apps
and then clcik on list of Application
After that you found your example name as Hello
Click on Hello link
Enjoy........
DOWNLOAD EXAMPLE
Downlod files and Extract in webapps folder
No comments:
Post a Comment