package int_2.servlets.assignments2; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import int_2.servlets.*; import int_2.tools.*; import int_2.beans.*; /** Please respect the copyright of this code. It is not allowed to copy this code and use at any circumstances. @author © Fredrik Andersson
This servlet uses code from my home made toolbox that you can find in the folder 8/tools and 8/beans. The toolbox is not ready yet, I have been working for it for a couple of years when I have time. The goal is to get a toolbox of classes so it will be easier to map tasks to use-case-diagram. This servlet collects a form that uses the post method */ public class PostMethodForms_2c extends GeneralServlet { public void start(HttpServletRequest request, HttpServletResponse response) throws IOException { Form form = FormManager.collectFormWithCheckBoxes(request); String output = createPage("applications/int_2/int_2/templates/post_method_forms.html", "post_method_forms"); if(form == null) { output = TextManager.replaceInString(output, "XXXPARAMETERLISTXXX", "Push button above."); } else { output = TextManager.replaceInString(output, "XXXPARAMETERLISTXXX", createParameterList(form)); } printString(output); flush(); } public String createParameterList(Form form) { StringBuffer stringBuffer = new StringBuffer(); String[] parameters = form.getAllKeys(); for(int i = 0; i < parameters.length; i++) { stringBuffer.append("
"); stringBuffer.append(parameters[i]); stringBuffer.append(" : "); if(form.get(parameters[i]) instanceof String) { stringBuffer.append((String)form.get(parameters[i])); } else if(form.get(parameters[i]) instanceof String[]) { String[] values = (String[])form.get(parameters[i]); for(int j = 0; j < values.length; j++) { stringBuffer.append(values[j]); if(j < values.length -1) { stringBuffer.append(", "); } } } } return stringBuffer.toString(); } }