我怎么这么妖?

06-03-01 big1980

我怎么这么妖? 
我在我的SiappController前加了个Validator内容如下
―――――――――――――――――――――――――――――――――――――――――
package web;

import org.springframework.validation.*;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

public class SiappValidator implements Validator{

public boolean supports(Class clazz) {
System.out.println("==supports==");
return SiappForm.class.isAssignableFrom(clazz);
//return clazz.equals(SiappForm.class);
}

public void validate(Object obj, Errors errors) {
System.out.println("==validate==");
SiappForm siappForm = (SiappForm) obj;
if (!siappForm.getUsername().equals("95494") 
|| !siappForm.getPassword().equals("123")) {System.out.println("==wrong=="+siappForm.getUsername());
errors.rejectValue("username","error.not-fit",null,"user name error!");
}
}
}
――――――――――――――――――――――――――――――――――――――――――
不管我怎么填Username和password,都只在这里返回了,是不是就是这样设计的?我的SiappController有问题吗?内容如下
―――――――――――――――――――――――――――――――――――――――――――
package web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.dao.DataIntegrityViolationException;

import java.io.IOException;
import java.net.BindException;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import logic.SiappFacade;

public class SiappController extends SimpleFormController {
/*private String formView;
private String successView;*/
private SiappFacade siApp;

public void setPetStore(SiappFacade siApp) {
this.siApp = siApp;
}

/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());

protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object cmd, BindException errors)
throws ServletException, IOException {
System.out.println("==1111111111111111111111111111111111==");
String now = (new java.util.Date()).toString();
logger.info("returning hello view with " + now);

SiappForm siappForm = (SiappForm)cmd;

Map resultModel = new HashMap();
resultModel.put("now", now);
resultModel.put("user", "bighead");

if("1".equals(siappForm.getUsername()) && 
"1".equals(siappForm.getPassword())) { System.out.println("===success===");
return new ModelAndView(new RedirectView(this.getSuccessView()),"model",resultModel); 
} 
else { System.out.println("===fail===");
return new ModelAndView(new RedirectView(this.getFormView()),"model",resultModel); 
} 
}
/* 
protected Object formBackingObject(HttpServletRequest request) throws ServletException { 
SiappForm siappForm = new SiappForm(); 
siappForm.setUsername("THF"); 
return siappForm; 
}*/

/*
public String getFail_view() {
return formView;
}

public String getSuccess_view() {
return successView;
}

public void setFail_view(String argString) {
formView = argString;
}

public void setSuccess_view(String argString) {
successView = argString;
}*/
}
 7456,搞spring 搞了半天问题多多,。。。


<p>

猜你喜欢