TechnoBuzz

A Techno Blog, mainly about Java

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);
}

}

Advertisements

September 4, 2004 - Posted by | Servlets & JSP

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: