Servlets – example1
Servlet model which others will extend:
public abstract class AbbyServlet extends HttpServlet {
protected void forward(HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse,
String s) throws ServletException, IOException {
RequestDispatcher requestdispatcher = getServletContext().getRequestDispatcher(s);
requestdispatcher.forward(httpservletrequest, httpservletresponse);
}
protected void checkSession(HttpServletRequest httpservletrequest,
HttpServletResponsehttpservletresponse)
throws specSessionException, specHttpSessionException {
try {
specSession ssession = null;
if(httpservletrequest.getSession() == null)
throw new specHttpSessionException();
ssession = getspecSession(httpservletrequest);
if(ssession == null)
throw new specSessionException();
catch(IllegalStateException illegal1) {
throw new specSessionException(illegal1.getMessage());
}
protected specSession getspecSession(HttpServletRequest httpservletrequest) {
HttpSession httpsession = null;
try {
httpsession = httpservletrequest.getSession();
}
catch(Exception exception) {
System.out.println(“SESSION ERROR: getSession(): ” + exception.getMessage());
}
if(httpsession == null) return null;
Object obj = null;
try {
obj = httpsession.getValue(“theSession”);
}
catch(Exception exception1) {
System.out.println(“SESSION ERROR: getValue(): ” + exception1.getMessage());
}
if(obj instanceof specSession)
return (specSession)obj;
else return null;
}
protected void setspecSession(specSession ssession, HttpServletRequest httpservletrequest) {
HttpSession httpsession = httpservletrequest.getSession();
httpsession.putValue(“theSession”, ssession);
}
}
No comments yet.
Leave a Reply