The Daily WTF
Luke has inherited a Java Struts-based application. Struts is one of the many Java web frameworks, designed around having HTTP requests trigger actions– that is routing HTTP requests to a specific function call.
Now, on one screen, the user filled in a form, and then the corresponding action on the server side needed to read the form data for an eventId and act upon it. In Struts, this can be very simple:
int event_id = Integer.parseInt(request.getParameter(“event_id”));
That’s the assumed way of doing that. But if you don’t learn how to use the framework properly, you might end up writing something else:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int event_id = 0; try { InputStream is = request.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String eventStr = “”; StringBuffer buff = new StringBuffer(); String line; do { line =
To read the full article click on the 'post' link at the top.