2.关于关闭Struts2自动验证的烦人英文问题。
应该有不少使用Struts2的人都是从Struts1过来的,但Struts2和Struts1是完全不同的,所以在配置Struts2的时间,难免有点畏缩,喜欢用它的默认配置。比如在自己建立的Struts.xml里,大家一般都这么写:
xml 代码
- <!---->
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
-
- <include file="struts-default.xml" />
- <include file="struts_xml/welcome.xml" />
- <include file="struts_xml/employee.xml" />
- <include file="struts_xml/department.xml" />
- <include file="struts_xml/nunEnterprise.xml" />
- <include file="struts_xml/enterprise.xml" />
- <include file="struts_xml/foreignEnterprise.xml" />
- <include file="struts_xml/exhibition.xml" />
- <include file="struts_xml/training.xml" />
- <include file="struts_xml/serviceEnterprise.xml" />
- <include file="struts_xml/mailController.xml" />
- <include file="struts_xml/enterpriseSearchController.xml" />
- <include file="struts_xml/foreignEnterpriseSearchController.xml" />
- <include file="struts_xml/serviceEnterpriseSearchController.xml" />
- <include file="struts_xml/nunEnterpriseSearchController.xml" />
- <include file="struts_xml/jChartController.xml" />
-
-
- <package name="default" extends="struts-default">
- <global-results>
- <result name="Exception">/exception.jspresult>
- <result name="SQLException">/exception.jspresult>
- global-results>
-
-
- <global-exception-mappings>
- <exception-mapping exception="java.sql.SQLException"
- result="SQLException" />
- <exception-mapping exception="java.lang.Exception"
- result="Exception" />
- global-exception-mappings>
- package>
-
- struts>
里面有一个叫“struts-default.xml”, 这是Struts2默认的重要配置文件。而且interceptor默认的配置为:
xml 代码
- <interceptor-stack name="defaultStack">
- <interceptor-ref name="exception"/>
- <interceptor-ref name="alias"/>
- <interceptor-ref name="servletConfig"/>
- <interceptor-ref name="prepare"/>
- <interceptor-ref name="i18n"/>
- <interceptor-ref name="chain"/>
- <interceptor-ref name="debugging"/>
- <interceptor-ref name="profiling"/>
- <interceptor-ref name="scopedModelDriven"/>
- <interceptor-ref name="modelDriven"/>
- <interceptor-ref name="fileUpload"/>
- <interceptor-ref name="checkbox"/>
- <interceptor-ref name="staticParams"/>
- <interceptor-ref name="params">
- <param name="excludeParams">dojo\..*param>
- interceptor-ref>
- <interceptor-ref name="conversionError"/>
- <interceptor-ref name="validation">
- <param name="excludeMethods">input,back,cancel,browseparam>
- interceptor-ref>
- <interceptor-ref name="workflow">
- <param name="excludeMethods">input,back,cancel,browseparam>
- interceptor-ref>
- interceptor-stack>
是不是什么interceptor都给你加载了。如果你这个时候使用了Validation.xml,那么一旦出现类型转换错误的失误,就会出现一些烦的英文,解决办法是:
xml 代码
- <!---->
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
-
- <package name="employee" extends="default">
-
- <interceptors>
- <interceptor-stack name="modefied">
- <interceptor-ref name="exception" />
- <interceptor-ref name="alias" />
- <interceptor-ref name="servlet-config" />
- <interceptor-ref name="prepare" />
- <interceptor-ref name="i18n" />
- <interceptor-ref name="chain" />
- <interceptor-ref name="debugging" />
- <interceptor-ref name="profiling" />
- <interceptor-ref name="scoped-model-driven" />
- <interceptor-ref name="model-driven" />
- <interceptor-ref name="fileUpload" />
- <interceptor-ref name="checkbox" />
- <interceptor-ref name="static-params" />
- <interceptor-ref name="params" />
-
- <interceptor-ref name="validation">
- <param name="excludeMethods">
- input,back,cancel,browse
- param>
- interceptor-ref>
- <interceptor-ref name="workflow">
- <param name="excludeMethods">
- input,back,cancel,browse
- param>
- interceptor-ref>
- interceptor-stack>
- interceptors>
- <default-interceptor-ref name="modefied" />
-
-
-
-
-
- <action name="employeeLogin"
- class="cn.gov.tdb.controller.EmployeeLoginController"
- method="login">
- <result name="success">welcome.jsp?active=1result>
- <result name="input">login.jspresult>
- action>
-
- <action name="employeeLogout"
- class="cn.gov.tdb.controller.EmployeeLoginController"
- method="logout">
- <result name="success">index.jspresult>
- <result name="input">index.jspresult>
- action>
-
-
-
-
-
- <action name="employeeCRUD"
- class="cn.gov.tdb.controller.EmployeeController"
- method="saveEmployee">
- <result name="success">welcome.jsp?active=1result>
- <result name="input">employeeForm.jspresult>
- action>
-
- <action name="listEmployees"
- class="cn.gov.tdb.controller.EmployeeController"
- method="listEmployees">
- <result name="success">listEmployees.jspresult>
- <result name="input">listEmployees.jspresult>
- action>
-
-
- package>
- struts>
自己重定义一个interceptor, 把
xml 代码
- <interceptor-ref name="conversionError"/>
删除就可以了。这样,烦人的英文就解决了~~~~~~~