Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Advanced Java Basic Questions

Advanced java basic questions

Uploaded by

Akshi Chhangani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Advanced Java Basic Questions

Advanced java basic questions

Uploaded by

Akshi Chhangani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q1. Take input from the user i.e.

, your name and print welcome on the


next servlet(use of servlet).
Index.html
<!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>
NewServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
char a;
try ( PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1> Welcome " + request.getParameter("uname")
+ "</h1>");
out.println("</body>");
out.println("</html>");
}}}

Output
Q2. Take input from the user i.e., your name and print welcome on
the next servlet(use of JSP).
Index.Html
<!DOCTYPE html>
<html>
<head>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
</head>
<body>
<form action="newjsp1.jsp" method="GET">
<label> Enter your name :</label>
<input type="text" name="uname"><br>
<input type="submit">
</form>
</body>
</html>
newjsp1.jsp
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String n = request.getParameter("uname");
out.println("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)
Index.html
<!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>

Servlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try ( PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample
code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
String n= request.getParameter("colors");
out.println("<body style='background-color:"+n+"'> Color
changed");
out.println("</body>");
out.println("</html>");
}
}
}
Output:

You might also like