Struts comes with example introduction

xiaoxiao2021-03-06  64

In recent days, many friends started to study Struts brought examples and have a lot of problems. I also returned a lot of posts, but the amount of question was not reduced, so I decided to write a presentation. It is not very detailed, mainly for each problem point for the post. JSP screen

Registration.jsp

Registration.jsp is used by client checks.

Form:

οnsubmit = "Return ValidateRegistrationform (this);">

The rear of the code is:

DynamicjavaScript = "true"

StaticjavaScript = "false" />

The ValidateRegistrationForm (this) in the form tag is corresponding to the value of the FormName (Registrationform).

The FormName RegistrationForm must match the form name in Struts-Config.xml and Validation.xml files.

The Type of the Registrationform can be seen in Struts-Config.xml is Org.Apache.Struts.validator.DynavalidatorForm. DynavalidatorForm is an From class of Struts, you only need to define the Form-property in struts-config.xml.

Validation.xml Configuring the appropriate check requirements, the verification rules are defined in Validator-Rules.xml. Several valids for Registrationform are self-contained, and we can also define themselves (if you have time in the future, I plan to say this).

HTML: DynamicJavaScript = "true" staticjavascript = "false" in JavaScript

It is a dynamic JavaScript script that does not implement a static JavaScript script.

Then introduced StaticJavaScript.jsp, there is this JSP screen.

Recover the parameters, do not implement dynamic JavaScript scripts, implement static JavaScript scripts. Take Subscription.jsp as an example, introduce server-side check, resource binding, and internationalization.

Subscription.jsp

Subscription.jsp is used by server-side checks.

Subscription. JSP screen The corresponding action is SAVESUBSCRIPTION.

There is a check function validate in the SubscriptionForm.

The Validate function verified by Host, UserName, Password, and Type, respectively. If there is an error, generate the corresponding actionerror, then put it in an ActionerRors object, and finally returns this object.

Resource binding:

Describes the error message used in Actionerror error.host.required, which is saved to the resource file. The resource file has several ApplicationResources.properties, ApplicationResources_ja.properties, ApplicationResources_ru.properties. If your IE default language is in English, the ActionServlet will take the information you need in the applicationResources.properties this file. If your IE default language is Japanese, the ActionServlet will take the ActionServlet to ApplicationResources_ja.properties file when you visit. Information required. If your default language is Chinese, ActionServlet can't find the corresponding resource file, it uses ApplicationResources.properties in English.

Resource binding also supports internationalization (I18N - 18 characters between I and N). You can create ApplicationResources_xx.properties for other languages ​​of ISO language code to XX.

In addition to English, Chinese and Japanese, in English, Chinese and Japanese, etc., you can use Java's own native2ascii.exe to transfer.

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

New Post(0)