-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prog02.java
30 lines (22 loc) · 1008 Bytes
/
Prog02.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//a servlet to receive data of a dropdown from html form and process it
import javax.servlet.*; //ServletException
import javax.servlet.http.*; //HttpServlet class
//HttpServletRequest,HttpServletResponse
//HttpServlet is a subclass of GenericServlet. It is more powerful & typically used when data is sent through frontend and
//to be processed for advance features like sessions
import java.io.*;// PrintWriter
public class Prog02 extends HttpServlet
{
//override the doPost() of this class
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
// get/collect the value sent by html paramter select with name=collect
String colname = req.getParameter("col");
pw.println("<html><body>");
pw.println("<h3><font color='" + colname + "'>It seems your favourite colour is " + colname + "</font></h3>");
pw.println("</body></html>");
pw.close();
}
}