|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.GenericServlet | +--javax.servlet.http.HttpServlet | +--com.ora.jsp.servlets.PBControllerServlet
This class is an example of a servlet used as the Controller for the Project Billboard application.
It initializes a number of servlet context attributes in its init() method. The doGet()/doPost() methods perform authentication and access control, and perform the action specified by the action request parameter is the client is authorized.
Fields inherited from class javax.servlet.http.HttpServlet |
HEADER_IFMODSINCE, HEADER_LASTMOD, LSTRING_FILE, lStrings, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE |
Fields inherited from class javax.servlet.GenericServlet |
config |
Constructor Summary | |
PBControllerServlet()
|
Method Summary | |
void |
destroy()
Removes the EmployeeRegistryBean and NewsBean servlet context attributes. |
private void |
doAuthenticate(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Autheticates a user with help from the EmployeeRegistryBean, using the "userName" and "password" request parameters. |
private void |
doForwardToLogin(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Forwards the request to the login JSP page, with an "errorMsg" parameter containing text to be displayed on the login page. |
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Processes a GET request by calling doPost(). |
private void |
doLogout(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Invalidates the session, thereby removing the authentication token, and redirects to the login page. |
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Performs authentication, if needed, and access control. |
private void |
doShowPage(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Forwards to the specified JSP page. |
private void |
doStoreMsg(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Creates a new NewsItemBean and sets its properties based on the "category" and "msg" request parameters, plus the firstName and lastName properties of the authenticated user (an EmployeeBean accessible as the "validUser" session attribute). |
private void |
doUpdateProfile(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Updates the projects property of an authenticated user, represented by the "validUser" session attribute, using the EmployeeRegistryBean. |
private void |
forward(java.lang.String url,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Forwards the request to the specified relative URL. |
private java.lang.String |
getShowPageURL(javax.servlet.http.HttpServletRequest request)
Returns an absolute URL, suitable for redirecting a request back to this servlet, with an "action" parameter set to "showPage" and a "page" parameter set to the specified (relative) page URL. |
void |
init()
Creates an EmployeeRegistryBean and a NewsBean, and saves them as servlet context attributes. |
private boolean |
isAuthenticated(javax.servlet.http.HttpServletRequest request)
Returns true if an authentication token object is found in the session. |
Methods inherited from class javax.servlet.http.HttpServlet |
|
Methods inherited from class javax.servlet.GenericServlet |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
Constructor Detail |
public PBControllerServlet()
Method Detail |
public void init() throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
public void destroy()
destroy
in class javax.servlet.GenericServlet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
doGet
in class javax.servlet.http.HttpServlet
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
doPost
in class javax.servlet.http.HttpServlet
private boolean isAuthenticated(javax.servlet.http.HttpServletRequest request)
private void doForwardToLogin(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
private void doAuthenticate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
Cookies with the user name and password are set or reset as specified by the "remember" request parameter.
private void doLogout(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
private void doStoreMsg(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
private void doUpdateProfile(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
private void doShowPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
private java.lang.String getShowPageURL(javax.servlet.http.HttpServletRequest request)
private void forward(java.lang.String url, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |