Our first step began to configure Tomcat connection pool
First we put the mysql's JDBC driver to $ {tomcat_home} / circat_home} / common / lib, change the MyWeb settings as follows
Workdir = "E: / dev / myweb / work / org / apache / jsp">
Set the JNDi name of the connection pool -> TYPE = "javax.sql.datasource" />
Factory class -> parameter>
Connection pool basic settings -> parameter> parameter> parameter> We write resource files Password = Password format error font> UserName = account format error font> HBM.Session.Error = Establish an Hibernate Session error. No.user = This is not found to have users. HBM.Session.Query = Hibernate HQL query error. Errors.Header = font color = red> Errors.footer = ul> font> Logon = landing Logon.username = account number Logon.password = password Save to C: /1.txt Then run Native2ascii -Encoding GBK C: /1.TXT C: /ApplicationResources_zh_cn.properties Will be generated C: /ApplicationResources_zh_cn.properties to copy to the src directory, we re-run this login program. There is garbled, we forgot to set the JSP page encoding into UTF-8, add ContentType = "text / html; charSet = UTF-8", refresh again OK success When you enter Chinese in the account box, it will appear in the picture. There is a garbled, such a case solution has 3: 1. Set Response to coding in each action, this method is more cumbersome, and each Action must be set once. 2. Use the filter in servlet2.3, unified settings 3. Overload the Process function in the ActionServlet. The first method is difficult to obtain an encoding method through an XML configuration. 2, 3 can be solved by configuring parameters in Web.xml This article describes how to use it, filter Filter There is a ready-made coded filter under the Filter folder inside the Samples in Tomcat. Copying, in Eclipse uses reconstruction, solve the Package mismatch problem. The following is a web.xml for this filter.
Filter -> init-param> filter> filter-mapping>
end -> Start Tomcat test again, OK. 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. Validator-rules.xml file validator-rules.xml file Define the validator that the application can use. Validator-rules.xml acts as a template's role, define the validator that all applications may be used. Below we redesigned our logonform Change to Public Class logonform extends ValidatorForm / * Actionform * / We commented out an ActionForm's validate () function. We configure the struts-config.xml file, and the file is finally increased. plug-in> Let's modify the validation.xml file increase
Property = "Username" Depends = "Required"> field> Property = "Password" Depends = "Required"> form> Increase in resource files Errors.Required = {0} is required. Restart the program, then the login program server is authenticated. Let's add the Client's JavaScript authentication. Modify logon.jsp <% @ 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"%>
hEAD>
οnsubmit = "Return ValidateLogonform (this)"> html: Submit> html: form>
html>
OK
Next, press the Excel program to start implementing the previous thoughts.
Download Excel Plan, this period source file