Struts2 Validator Validation form avoids invalid SQL query

Source: Internet
Author: User

General web Landing, the simplest is the user name and password, but the user may not follow the correct format to enter the resulting SQL query will be triggered, but this kind of query will greatly increase the burden on the site. To avoid such problems, we can use the STRUTS2 validator to accomplish the results we want.


Let's say we have a form like this:

User name: <s:textfield name= "LoginName" cssclass= "MSG" ></s:textfield>
Password: <s:password name= "loginpwd" cssclass= "MSG" ></s:password>

now we need to set the calibration configuration, generally in the development of this type of configuration and the login module of the action interceptor placed under a package:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE validators Public "-//apache struts//xwork Validator 1.0.3//en" "http://struts.apache.org/dtds/ Xwork-validator-1.0.3.dtd "><!--default return input--><validators><!--1 login user--><field name=" LoginName "><!--1.1 required--><field-validator type=" requiredstring "><message> login username cannot be empty </ message></field-validator><!--1.2 length--><field-validator type= "stringlength" ><param name= " MaxLength ">14</param><param name=" minLength ">2</param><message> login username must be in ${minlength}- ${maxlength} between characters </message></field-validator></field><!--login password--><!--1 logged in user-->< Field name= "Loginpwd" ><!--1.1 required--><field-validator type= "requiredstring" ><message> login password cannot be empty </message></field-validator><!--1.2 length--><field-validator type= "Stringlength" ><param Name= "MaxLength" >16</param><param name= "MinLength">4</param><message> login Password must be between ${minlength}-${maxlength} characters </message></field-validator> </field></validators>

of course, if you end up like this, there are still problems, so look at the problem.

Open the developer mode

<!--development mode--><constant name= "Struts.devmode" value= "true" ></constant>

Struts problem Reportstruts has detected a unhandled exception:Messages:No result defined for action Com.canyugan.crm.sta Ff.web.action.StaffAction and result Inputstacktracesno result defined for action Com.canyugan.crm.staff.web.action.StaffAction and result input

What do you mean? The type result returned as input is not defined in the action. So we also need to add a sentence in the current struts configuration file:

<result name= "Input" >/WEB-INF/pages/login.jsp</result>

Here I set the turning page as the landing page.


This allows us to complete the configuration, refresh the page input illegal data, the validator will open the work, and the server can not see Hibernate query statement.


Struts2 Validator Validation form avoids invalid SQL query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.