write the following code and follow the steps as below:
index.html:
<html><body>
<form action="welcome" method="get">
Enter your name<input type="text" name="name"><br>
<input type="submit" value="login">
then new server window will open as below:
Now, click on the HEERA and new window will open as below:
Enter name of a person and click on login button.
index.html:
<html><body>
<form action="welcome" method="get">
Enter your name<input type="text" name="name"><br>
<input type="submit" value="login">
web.xml
<web-app>
<servlet>
<servlet-name>BABU</servlet-name>
<servlet-class>HEERA</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BABU</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
HEERA.java
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class HEERA extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String name=req.getParameter("name");
pw.println("Welcome "+name);
}}
now compile the above folder as below:
Now to complete the project follow the hierarchy of file:
step1. create a folder and name the folder as your project name.
folder name; HEERA
step2. make index.html and WEB-INF in HEERA folder
step3. Create web.xml and a folder classes in WEB-INF
step4. copy the HEERA.class file in classes folder.
Finally, project is completed.
Start the server as below:
Now you need to write url in browser as below:
(1) if your tomcat server has port 8088 then write url as
http://localhost:8088/
otherwise, if your tomcat server has port 8080 then write url as
http://localhost:8080/
then new server window will open as below:
Now, a new open window will open and the project HEERA folder will show on the the server on Applications tables as below:
Now, click on the HEERA and new window will open as below:
Enter name of a person and click on login button.
Then, finally servlet load the name on bowser that you have entered.