Experience the real struts development 3 (3)

zhaozj2021-02-17  65

Below start processing JSP page error

Add an error page, the content is as follows:

<% @ Page ContentType = "Text / HTML; Charset = UTF-8"%>

<% @ page isrrorpage = "true"%>

... other omitted, please see the source file

When you want to handle Exception on other pages, just add it on the head

<% @ Page ErrorPage = "Error.jsp"%>

The test is as follows:

<% @ page language = "java" contenttype = "text / html; charSet = UTF-8"%>

<% @ Taglib Uri = "/ Tags / Struts-Bean" prefix = "bean"%>

<% @ Taglib URI = "/ Tags / Struts-HTML" prefix = "html"%>

<% @ Page ErrorPage = "Error.jsp"%>

<%

INT n = 0;

INT N1 = 10 / N;

%>

Turn the error page when requesting:

Test the Exception in the action below.

Now let's start processing for an exception definition in the action.

Configure global Exception first

Modify our logonAction so that it throws an exception. Such a global configuration file can be processed.

The above verification is through the Server terminal, we inherit ActionForm, in fact, we have a simpler way, that is, using the Validator component.

Using the Validator component, you can support both the client's verification, while the Server end is also verified. At the same time, the verification method can be reused.

Let's meet the Validator of Struts1.1.

1. Validators A Validator is a Java class that calls the Validator framework when performing a verification rule. The framework calls this Validaotor class based on the method defined in the configuration file. In general, each Validator class provides a separate verification rule, and then these rules can be combined into a more complex rule set. The Validator framework provides most of the validation rules that the web application needs. You can use these existing verification rules to create your own verification profile. We can also add more Validator as needed.

2. Profile

Struts1.1 Validator Framework, uses the two profiles, one called Validator-Rules.xml, another called Validation.xml; actually you can also name them at will, and you can even merge them into an XML file. However, you are still best to separate them because they have their own uses.

转载请注明原文地址:https://www.9cbs.com/read-30016.html

New Post(0)