請高人幫我看看webwork使用Validator驗證的問題

zhangbo198294發表於2005-04-05
xwork.xml:
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd";>

<xwork>
<include file="webwork-default.xml" />
<package name="default" extends="webwork-default">
<interceptors>
<interceptor-stack name="modelParamsStack">
<interceptor-ref name="params" />
<interceptor-ref name="model-driven" />
<interceptor-ref name="validationWorkflowStack" />
</interceptor-stack>
</interceptors>
<action name="login" class="MyTest.LoginAction">
<result name="success" type="dispatcher">
<param name="location">/main.jsp</param>
</result>
<result name="loginfail" type="dispatcher">
<param name="location">/index.jsp</param>
</result>
<interceptor-ref name="modelParamsStack" />
</action>
</package>
</xwork>

validators.xml:
<validators>
<validator name="required" class="com.opensymphony.webwork.validators.javascriptRequiredFieldValidator"/>
<validator name="requiredstring" class="com.opensymphony.webwork.validators.javascriptRequiredStringValidator"/>
<validator name="int" class="com.opensymphony.webwork.validators.javascriptIntRangeFieldValidator"/>
<validator name="date" class="com.opensymphony.webwork.validators.javascriptDateRangeFieldValidator"/>
<validator name="expression" class="com.opensymphony.xwork.validator.validators.ExpressionValidator"/>
<validator name="fieldexpression" class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator"/>
<validator name="email" class="com.opensymphony.webwork.validators.javascriptEmailValidator"/>
<validator name="url" class="com.opensymphony.webwork.validators.javascriptURLValidator"/>
<validator name="visitor" class="com.opensymphony.webwork.validators.javascriptVisitorFieldValidator"/>
<validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork.validator.validators.StringLengthFieldValidator"/>
</validators>

LoginAction-validation.xml:
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN""http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd";>
<validators>
<field name="model.username">
<field-validator type="required">
<message>Please enter Username!</message>
</field-validator>
</field>
<field name="model.password">
<field-validator type="stringlength">
<param name="minLength">4</param>
<param name="maxLength">6</param>
<message>
Password length must between ${minLength} and ${maxLength} chars!
</message>
</field-validator>
</field>
</validators>


LoginAction.java:
package MyTest;

import java.util.Map;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
import com.opensymphony.xwork.ModelDriven;

public class LoginAction extends ActionSupport implements Action,ModelDriven{

private final static String LOGIN_FAIL="loginfail";
LoginInfo loginInfo = new LoginInfo();
public String execute() throws Exception {
if ("erica".equalsIgnoreCase(loginInfo.getUsername())
&& "mypass".equals(loginInfo.getPassword())) {
//將當前登入的使用者名稱儲存到Session
ActionContext ctx = ActionContext.getContext();
Map session = ctx.getSession();
session.put("username",loginInfo.getUsername());
//出於演示目的,透過硬編碼增加通知訊息以供顯示
loginInfo.getMessages().add("message1");
loginInfo.getMessages().add("message2");
loginInfo.getMessages().add("message3");
return SUCCESS;
}else{
loginInfo.setErrorMessage("Username/Password Error!");
return LOGIN_FAIL;
}
}
public Object getModel() {
return loginInfo;
}
}
執行時後臺就出錯了! 異常:
2005-4-4 16:10:10 com.opensymphony.xwork.validator.ValidatorFileParser$2 fatalEr
ror
嚴重: White spaces are required between publicId and systemId. at (1:77)
2005-4-4 16:10:10 com.opensymphony.xwork.validator.ValidatorFileParser parseActi
onValidators
嚴重: Caught exception while attempting to load validation configuration file.
org.xml.sax.SAXParseException: White spaces are required between publicId and sy
stemId.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.document.uilderImpl.parse(Unknown Source)
at javax.xml.parsers.document.uilder.parse(Unknown Source)
at com.opensymphony.xwork.validator.ValidatorFileParser.parseActionValid
ators(ValidatorFileParser.java:81)

請高人幫我看看!!!!!

相關文章