Wednesday, January 25, 2012

Basic Servlet Practice

A project of really basic practice, not good practice, just practice.

You can download the basic practice project from github
https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/BasicServletPractice

Description:

index.html

This page practice two things:
Use AJAX to get the hint of id and password,
it send the http get request to context 'auth.hint',

Use form submit to do login,
the submit form action is the http post to context 'login.go',

error.jsp

This is the error page defined in 'web.xml',
it simply display the exception message

the exception is from login servlet

content.html

This page practice JSON,
it use AJAX to get the content from ContentServlet,
and use eval method to transfer the content to array,
the array combined by a string and two inner array,
the first string is a javascript command which executed by eval method,
the two inner array are the content and displayed by that command.

If it receive the bad request status,
it will redirect to login page

Hint.java

This file practice set/get attribute from session,
output the text to client and config servlet by annotation.

It provide the hint of id and password,
or show alert message if ask too much times.

Login.java

This file practice get parameter from request,
redirect to another page.
It config in web.xml

It get the input id and password,
if it is correct, redirect to content page,
throw ServletException with message 'Login fail' otherwise

Content.java

This file practice JSON,
it also config by annotation.

It create two small JSON array,
then put a command that will execute at client and
the two small array into a big one.

** To use JSON, the jars below are required
json-lib-2.4-jdk15.jar, ezmorph-1.0.6.jar, commons-logging-1.1.1.jar,
commons-lang-2.5.jar, commons-collections-3.2.1.jar, commons-beanutils-1.8.3.jar

Ref: http://json-lib.sourceforge.net/

Logout.java

This file invalidate the session then redirect to login page.

ReqFilter.java

This file practice the filter, and config filter by annotation

This is a filter protect the content page,
it triggered by the 'content.gen' context
(the content page send request to it to get content)

if a session do not contain the 'Login' data,
the request can not pass this filter and will get the 'bad request' status.

No comments:

Post a Comment