Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/web/jsp/AbstractJSPPage.java @ 0:3e62083dbcbf
First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
author | "jurzua <jurzua@mpiwg-berlin.mpg.de>" |
---|---|
date | Thu, 23 Apr 2015 15:46:01 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/AbstractJSPPage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,92 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public abstract class AbstractJSPPage { + + protected HttpServletRequest request; + protected HttpServletResponse response; + + public HttpServletRequest getRequest() { + return request; + } + public void setRequest(HttpServletRequest request) { + this.request = request; + } + public HttpServletResponse getResponse() { + return response; + } + public void setResponse(HttpServletResponse response) { + this.response = response; + } + + public void addMsg(String msg){ + if(getSessionBean().getMsgList() == null){ + getSessionBean().setMsgList(new ArrayList<String>()); + } + getSessionBean().getMsgList().add(msg); + } + + public void init(){ + Map<String, String[]> parameters = request.getParameterMap(); + for(String parameter : parameters.keySet()) { + System.out.println(parameter + "= " + printVars(parameters.get(parameter))); + } + } + + public String getParameter(String name){ + String[] array = request.getParameterValues(name); + if(array != null && array.length > 0){ + return array[0]; + } + return new String(); + } + + public Long getLongParameter(String name){ + String param = getParameter(name); + try { + return Long.parseLong(param); + } catch (Exception e) { + } + return null; + } + + public Integer getIntParameter(String name){ + String param = getParameter(name); + try { + return Integer.parseInt(param); + } catch (Exception e) { + } + return null; + } + + public String printVars(String[] array){ + String response = new String(); + for(String s : array){ + response += s + ", "; + } + return response; + } + + + public void internalError(Exception e){ + addMsg("Internal Error: " + e.getMessage()); + e.printStackTrace(); + } + + public SessionBean getSessionBean(){ + SessionBean bean = (SessionBean)((HttpServletRequest) request).getSession().getAttribute("sessionBean"); + if(bean == null){ + ((HttpServletRequest) request).getSession().setAttribute("sessionBean", new SessionBean()); + } + return (SessionBean)((HttpServletRequest) request).getSession().getAttribute("sessionBean"); + } + + public ApplicationBean getApplicationBean(){ + return ApplicationBean.getInstance(); + } +}