package com.cv.jsp.el.attribute;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
/**
* Servlet implementation class ServletAttributeImpl
*
* @author Chandra Vardhan
*/
public class ServletAttributeImpl extends HttpServlet {
private static final Logger LOGGER = Logger
.getLogger(ServletAttributeImpl.class);
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
LOGGER.info("LOGGER : ServletAttributeImpl doGet(HttpServletRequest,HttpServletResponse)");
res.setContentType("text/html");
String name = req.getParameter("name");
String id = req.getParameter("empId");
String food = req.getParameter("food");
Person person = new Person();
person.setName(name);
person.setEmpId(Integer.parseInt(id));
Dog dog = new Dog();
dog.setName("Jokey");
Toy t1= new Toy();
t1.setName("toy1");
Toy t2= new Toy();
t2.setName("toy2");
Toy t3= new Toy();
t3.setName("toy3");
dog.setToys(new Toy[]{t1,t2,t3});
person.setDog(dog);
req.setAttribute("person", person);
req.setAttribute("foo.person", person);
Map<String, String> map = new HashMap<String, String>();
map.put("key1", "Baapu");
map.put("key2", "Akka");
map.put("key3", "Amma");
req.setAttribute("map", map);
String[] companies = {"Google","Amazon","Salesforce"};
req.setAttribute("companies", companies);
RequestDispatcher rd = req.getRequestDispatcher("result.jsp");
rd.forward(req, res);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("LOGGER : ServletAttributeImpl doGet(HttpServletRequest ,HttpServletResponse )");
doPost(request, response);
}
} |
No comments:
Post a Comment