want
Tapestry develops a web application, a little difficult for a novice,
Tapestry is different from
The previous Web Presentation Framework, so it is not possible, and the learning curve is longer. This is a fact.
Let me talk about a general structure of a web application:
With jbuider9 as a development tool, you must first create a project, for example, the name is
TapestryExmaple, it
Workspace is f: / myproject /
TapeStryExmaple. The subdirectory and files below it are
BAK - this is a BACKUP directory of JBuider.
Build - My Ant's Work Contents, my Ant will use this catalog to compile packaging.
Classes - JBuilder Compiles Class Directory
Configs - where some of my configuration files are placed
Lib - the directory where I have to use the library file
Context - my web application's context directory
DOC - my documentation catalog
SRC - Directory of my Java Source
Build.properties - Attribute settings file for Ant
BUILD.XML - Definition file for Ant work
After you build this project, you need to build a Web Application, click File -> New -> Web -> Web
Application, because we need to use Tomcat4.1 debugging in JBuilder, use jboss3.x or not, but you
To download a plugin called entwizard_jboss3x_jb9_v3-1-5.zip, JBuiderx provides JB
OSS support, but JBuiderx often has some inexplicable blame, and is slower, I am not used.
When you build a web application, you have to enter both Name and Directory, name
PatientRecord, pay attention to the Name you entered here, will appear in the URL you will test in the future:
Your URL may be like this:
Http: // localhost: 8080 / patientRecord / app
The next app is configured in Web.xml, then say it.
Your web application's Directory value is the same as our scheduled, that is, the context directory,
Here is f: / myproject /
TapeStryExmaple / Context, this context directory is Web Applicatio
n
The core directory, which will be explained in detail below.
For example, there are three directories like my context directory.
Home - My WEB Applicattion Submodule Home's Context
There is a subdirectory CSS - placed the CSS file used by this submodule
Images - Place the image of this submodule (Icon)
Document: Home.html, Register.xml ...
These are HTML Template corresponding to the page in my word module.
PatientRecord - a child module of my web applicattion PatientRecord's Context
The directory structure is the same as the Home submodule
WEB-INF - the most core directory
The subdirectories and files below have
Classes - Your Java Classes will have a copy here.
LIB - Your engineering referenced by Lib here with a copy
PatientRecord.Application - you
TapeStry core configuration file
Web.xml - Web Application Core Profile
Let's take the two files of patientRecord.Application and Web.xml, and my sample file is as follows:
Web.xml
XML Version = "1.0" encoding = "UTF-8"?>
http://java.sun.com/dtd/web-app_2_3.dtd>
filter>
filter-mapping>
servlet>
servlet-maping>
session-config>
web-app>
This property has
Display-name - not important, just display name
Filter and filter-mapping configuration - do not move, use the default configuration,
Servlet configuration - this is very important, my servle name is PatientRecord, the corresponding class is
com.ht.web.patientRecordServlet, this is a class I developed by my own:
This class looks very simple:
Package com.ht.Web;
Import org.apache.tapestry.ApplicationServlet;
/ **
* @Version $ ID: SimpleServlet.java, V 1.9 2002/05/04 12:43:31 HSHIP EXP $
* @Author Howard Lewis SHIP
*
* /
Public Class PatienceRecordServlet Extends ApplicationServlet
{
}
You usually define a class extends org.apache.tapestry.applicationServlet.
Of course, if you have any special requirements, you can strengthen this class. Let me talk about this core class: This is actually a dispatcher, it accepts the outside world.
HTTP REQUEST request, then send the request to process
TapeStry Engine processing.
legend:
http://bbs1.nju.edu.cn/file/high-level-component-Request.p
Servlet-maping - this is the setting of the URL mapping, which is generally set to App
session-config>
This is the configuration of the Timeout for HTTP Session, here is 15 minutes.
Let's take another PatientRecord.Application file, which is also an XML file:
XML Version = "1.0" encoding = "UTF-8"?>
DOCTYPE Application Publication PUBLIC
"- // Apache Software Foundation //
TapeStry Specification 3.0 // en "
"
TapeStry_3_0.dtd "> http://jakarta.apache.org/tapestry/dtd/
TapeStry_3_0.dtd>
->
application>
We can see my Application name = "patient record system" by this document.
My engine-class is com.ht.web.patientRecordengine
My org.apache.tapestry.visit-class is com.ht.web.visitorState
The above two are Override
Tapestry's default implementation
This is my HOME-PAGE page pointing to my WEB Application Submodule Home HOME Page
->
These two items are me setting an error handling page
Where com.ht.Exception-Page is to handle ordinary org.apache.tapestry.ApplicationException,
It is now annotated, because the current development phase, I want to check the detailed error, don't have to be handled.
com.ht.security-exception-page is to process java.lang.securityException,
Because a website that needs to be logged in, a user who is logged in is not accessible to most resources.
If he visited the unacceptable resource, I will throw SECURITYEXCEPTION to the ENGINE process.
TapeStry Engine can define some service providing services, I define an Home service here is
I want to decide my home page page, not
Tapestry's default configuration page.
These two items are explained that my Application contains two library, which is actually a Web Application Split.
The means of submodules, such as /com/ht/home/home.library"/ corresponds to my Home submodule,
/Com/ht/patientRecord/PatientRecord.library corresponds to my PatientRecord submodule
Let me talk about it
TapeStry Engine, for example, my ENGINE is implemented as follows:
Package com.ht.Web;
Import java.io. *;
Import java.net.urlencoder;
Import javax.servlet.servletException; import javax.servlet.http.httpservletRequest;
Import javax.servlet.http.httpservletResponse;
Import javax.servlet.http.httpsession;
Import org.apache.tapestry. *;
Import org.apache.tapeengine;
Import org.apache.tapestry.Engine.iPropertySource;
Import org.apache.tapestry.Request.ResponseoutputStream;
Import org.apache.commons.lang.StringUtils;
/ **
* @Author Hery Tang
*
* Creation Date 2003-9-18
* Version 1.0
* /
Public class patientRecordengine Extends BaseEngine {
Public static final string home_page_name = "com.ht.home-page";
Public static final string exception_page_name = "com.ht.exception-page";
Public static final string security_exception_page_name = "com.ht.security-exception-page";
PRIVATE TRANSIENT BOOLEAN KILLSession;
Protected Void CleanuPafterRequest (Irequestcycle Cycle)
{
Super.cleanupafterRequest (cycle);
IF (KillSession)
{
Try
{
HttpSession session = cycle.getRequestContext (). Getsession ();
IF (session! = NULL)
{
session.INVALIDATE ();
}
}
Catch (IllegalStateException EX)
{
// ignore.
}
}
}
Public void logout ()
{
VisitorState Visit = (VisitorState) getvisit ();
IF (Visit! = NULL)
{
Visit.Setuser (NULL);
Visit = NULL;
}
Killsession = true;
}
/ **
* This methods read the home page name which defined by the user by using
* Propetry com.ht.home-page in Application Specification
*
* @Return the name of home page.
* /
Public string gethomepagename () {
Return getPropertySource (). getPropertyValue (Home_page_name);
}
/ **
* Return The security exception page name. If user does not defined this
* Page Name, The Normal Exception Page Will Be Return.
* @Return The name of the security exception page.
* /
Public string getsecurityExceptionPageName () {
String result =
GetPropertySource (). getpropertyvalue
Security_exception_page_name);
IF (stringutils.isempty (result) {
Result = getExceptionPageName ();
}
Return Result;
}
/ **
* Return The Exception Page Name. If User Does Not Defeed This Page Name,
* The Default Exception page will be return.
* @Return the name of the normal exception page.
* /
Public String getExceptionPageName () {
String result =
GetPropertySource (). getPropertyValue (Exception_page_name);
IF (stringutils.isempty (result) {
Result = super.getExceptionPageName ();
}
Return Result;
}
/ **
* Overide The Method To Support Security Exception.
* /
Protected Void ActivateExceptionPage
Irequestcycle Cycle,
ResponseoutputStream Output,
Throwable cause
Throws servletexception {
// Print It to console first
PrintExceptions (Cause);
Try {
String ExceptionPageName;
Throwable throwable = cause;
Throwable securityException = null;
Boolean ISSecurityException = false;
IF (throwable
InstanceOf org.apache.tapestry.applicationRuntimeException) {
ApplicationRuntimeException Exception =
ApplicationRunTimeException) throwable;
IF (Exception.getrootcause () instanceof securityException) {
SecurityException = Exception.getcause ();
ISsecurityException = true;
}
}
IF (ISSecurityException) {
ExceptionPageName = GetSecurityExceptionPageName ();
} else {
ExceptionPageName = getExceptionPageName ();
}
IPage ExceptionPage = Cycle.getPage (ExceptionPageName);
IF (SecurityException == NULL) {
ExceptionPage.SetProperty ("Exception", Cause);
} else {
ExceptionPage.SetProperty ("Exception", SecurityException;
CYCLE.Activate (ExceptionPage);
RenderResponse (Cycle, Output);
} catch (throwable ex) {
// Worst Case Scenario. The Exception Page Itself Is Broken, Leaving
// US with no option but to write the cause to the output.
REPORTEXCEPTION
TapeStry.getMessage
"Abstractenne.unable-to-process-client-request"),
Cause);
// Also, Write the Exception thrown when redendering the Exception
// page, so that can get fixed as well.
REPORTEXCEPTION
TapeStry.getMessage
"Abstract-Exception-Page",
EX);
// and throw the Exception.
Throw new servletexception (ex.getMessage (), EX);
}
}
Private Void PrintExceptions (Throwable throwable) {
IF (throwable == null) {
Return;
}
Throwable.printStackTrace ();
PrintExceptions (throwable.getcause ());
}
}
Public void logout ()
A user logs out, empties a state in the VisitorState object representing the user state,
Killsession flag is TRUE
Protected Void CleanuPafterRequest (Irequestcycle Cycle)
Overrride Parent class BaseEngine implementation, first call the parent class implementation and then look at the KillSession flag, if true, INVALIDATE SESSION.
Public string gethomePageName ()
Public string getsecurityExceptionPageName ()
Public String getExceptionPageName ()
It is to take out I am in the configuration of PatientRecord.Application.
Protected Void ActivateExceptionPage
Irequestcycle Cycle,
ResponseoutputStream Output,
Throwable cause
Override AbstractEngine is an implementation, handling various Exception in my own way.