Change background color using servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("Text/Html");
String c=req.getParameter("color");
PrintWriter pw=res.getWriter();
if(c.equals("red"))
pw.println("<body BGCOLOR=red>");
if(c.equals("green"))
pw.println("<body BGCOLOR=green>");
if(c.equals("green"))
pw.println("<body BGCOLOR=green>");
if(c.equals("blue"))
pw.println("<body BGCOLOR=blue>");
if(c.equals("yellow"))
pw.println("<body BGCOLOR=yellow>");
if(c.equals("black"))
pw.println("<body BGCOLOR=black>");
pw.println("<center><h2>The selected color is:"+c+"</h2></center>");;
pw.close();
}
}
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("Text/Html");
String c=req.getParameter("color");
PrintWriter pw=res.getWriter();
if(c.equals("red"))
pw.println("<body BGCOLOR=red>");
if(c.equals("green"))
pw.println("<body BGCOLOR=green>");
if(c.equals("green"))
pw.println("<body BGCOLOR=green>");
if(c.equals("blue"))
pw.println("<body BGCOLOR=blue>");
if(c.equals("yellow"))
pw.println("<body BGCOLOR=yellow>");
if(c.equals("black"))
pw.println("<body BGCOLOR=black>");
pw.println("<center><h2>The selected color is:"+c+"</h2></center>");;
pw.close();
}
}
HTML code
<HTML>
<HEAD>
<TITLE>
Color Change
</TITLE>
</HEAD>
<BODY>
<FORM method=get action="http://127.0.0.1:8080/examples/servlets/servlet/ColorServlet">
<CENTER>
Select Color :
<select name="color" id="color">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">yellow</option>
<option value="black">Black</option>
</Select>
<input type="submit" value="Submit">
</FORM>
</BODY>
</HTML>
<HEAD>
<TITLE>
Color Change
</TITLE>
</HEAD>
<BODY>
<FORM method=get action="http://127.0.0.1:8080/examples/servlets/servlet/ColorServlet">
<CENTER>
Select Color :
<select name="color" id="color">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">yellow</option>
<option value="black">Black</option>
</Select>
<input type="submit" value="Submit">
</FORM>
</BODY>
</HTML>
output
servlet color select |
change color using servlet |
Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
ReplyDeleteBest Devops Training in pune
Microsoft azure training in Bangalore
Power bi training in Chennai
This comment has been removed by the author.
ReplyDeleteNice post. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck.
ReplyDeleteDevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery
Very Helpful for Beginners
ReplyDeleteThank you for sharing the article. The data that you provided in the blog is informative and effective.Java training in chennai
ReplyDeletepython training in chennai
web designing and development training in chennai
selenium training in chennai
digital-marketing training in chennai