1 4 5 package com.sun.j2ee.blueprints.clientstate; 6 7 8 import java.io.*; 9 import java.util.*; 10 11 import org.apache.commons.codec.base64.Base64; 13 14 import javax.servlet.*; 16 import javax.servlet.http.*; 17 18 import com.sun.j2ee.blueprints.clientstate.deserialize.*; 19 20 24 public class WordServlet extends HttpServlet { 25 26 private ServletContext context = null; 27 28 public void init(ServletConfig config) throws ServletException { 29 this.context = config.getServletContext(); 30 } 31 32 public void doPost(HttpServletRequest request, 33 HttpServletResponse response) 34 throws IOException, ServletException { 35 ClientStateDeserializer.deserialize(request,response); 37 SampleBean bean = (SampleBean)request.getAttribute("sampleBean"); 38 if (bean == null) { 39 System.out.println("WordServlet: Creating a new SampleBean"); 40 bean = new SampleBean(); 41 request.setAttribute("sampleBean", bean); 42 } 43 String newWord = request.getParameter("newWord"); 44 if (!newWord.trim().equals("")) { 45 bean.addWord(newWord); 46 } 47 Map params = (Map)request.getParameterMap(); 49 Iterator it = params.keySet().iterator(); 50 while (it.hasNext()) { 51 String key = (String )it.next(); 52 if (key.startsWith("word_")) { 53 String [] values = (String [])params.get(key); 54 String valueString = values[0]; 55 bean.removeWord(valueString); 56 } 57 } 58 context.getRequestDispatcher("/index.jsp").forward(request, response); 59 } 60 } 61 62 | Popular Tags |