1 16 17 package examples.app1; 18 19 20 import java.io.IOException ; 21 import java.util.Hashtable ; 22 import java.util.Locale ; 23 import javax.servlet.RequestDispatcher ; 24 import javax.servlet.ServletException ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpSession ; 27 import javax.servlet.http.HttpServletResponse ; 28 import org.apache.struts.Globals; 29 import org.apache.struts.action.Action; 30 import org.apache.struts.action.ActionError; 31 import org.apache.struts.action.ActionErrors; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 import org.apache.struts.action.ActionServlet; 36 import org.apache.struts.util.MessageResources; 37 38 39 57 public class AddressAction extends Action 58 { 59 60 62 73 public ActionForward execute(ActionMapping mapping, 74 ActionForm form, 75 HttpServletRequest request, 76 HttpServletResponse response) 77 throws IOException , ServletException 78 { 79 String action; 80 HttpSession session; 81 82 ActionErrors errors = new ActionErrors(); 83 84 try 85 { 86 session = request.getSession(); 87 88 action = ((AddressForm)form).getAction(); 90 91 servlet.log("[DEBUG] AddressAction at perform(): Action ist " + action); 92 93 if ( action.equals("edit") ) 95 { 96 return (mapping.findForward("editAddress")); 98 99 } 100 else if (action.equals("save")) 101 { 102 AddressBean bean = (AddressBean)session.getAttribute("address"); 104 105 if (bean == null) 106 { 107 bean = new AddressBean(); 108 session.setAttribute("address", bean); 109 } 110 111 bean.setFirstname( ((AddressForm)form).getFirstname() ); 113 bean.setLastname( ((AddressForm)form).getLastname() ); 114 bean.setStreet( ((AddressForm)form).getStreet() ); 115 bean.setZip( ((AddressForm)form).getZip() ); 116 bean.setCity( ((AddressForm)form).getCity() ); 117 bean.setCountry( ((AddressForm)form).getCountry() ); 118 bean.setLanguages( ((AddressForm)form).getLanguages() ); 119 120 return (mapping.findForward("showAddress")); 122 123 } 124 else 125 { 126 String locale = ((AddressForm)form).getLocale(); 127 if (locale.equals("Deutsch")) 128 session.setAttribute(Globals.LOCALE_KEY, new Locale ("de", "")); 129 else 130 session.setAttribute(Globals.LOCALE_KEY, new Locale ("en", "")); 131 132 return (mapping.findForward("showAddress")); 134 } 135 } 136 catch (Exception e) 137 { 138 servlet.log("[ERROR] TskAction at final catch: " + e.getMessage()); 140 e.printStackTrace(); 141 142 } 143 144 return (mapping.findForward("showAddress")); 146 147 } 148 } 149 150 | Popular Tags |