Q1. Take input from the user i.e.
, your name and print welcome on the
next servlet(use of servlet).
[Link]
<!DOCTYPE html>
<html>
<body>
<form action="NewServlet" method="GET">
<label> Enter your name :</label>
<input type="text" name="uname"><br>
<input type="submit">
</form>
</body>
</html>
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
char a;
try ( PrintWriter out = [Link]()) {
[Link]("<!DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>Servlet NewServlet</title>");
[Link]("</head>");
[Link]("<body>");
[Link]("<h1> Welcome " + [Link]("uname")
+ "</h1>");
[Link]("</body>");
[Link]("</html>");
}}}
Output
Q2. Take input from the user i.e., your name and print welcome on
the next servlet(use of JSP).
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<form action="[Link]" method="GET">
<label> Enter your name :</label>
<input type="text" name="uname"><br>
<input type="submit">
</form>
</body>
</html>
[Link]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String n = [Link]("uname");
[Link]("Welcome "+ n); %>
</body>
</html
Output:
Q3. Choose color from the list box in HTML, and the chosen color
should be the background of
the servlet(use of sevlet)
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF
8">
</head>
<body>
<form action="NewServlet" method="GET">
<label>Choose color: </label>
<input type="color" name="colors" value="#e27979">
<input type="submit">
</form>
</body>
</html>
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
try ( PrintWriter out = [Link]()) {
/* TODO output your page here. You may use following sample
code. */
[Link]("<!DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>Servlet NewServlet</title>");
[Link]("</head>");
String n= [Link]("colors");
[Link]("<body style='background-color:"+n+"'> Color
changed");
[Link]("</body>");
[Link]("</html>");
}
}
}
Output: