标签:
package cn.itcast.shop.user.action;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.http.HttpRequest;
import org.springframework.web.context.support.ServletContextResource;
import cn.itcast.shop.user.service.UserService;
import cn.itcast.shop.user.vo.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class UserAction extends ActionSupport implements ModelDriven<User> {
private User user= new User();
private UserService userService;
public void setUserService(UserService userService) {
this.userService = userService;
}
@Override
public User getModel() {
// TODO Auto-generated method stub
return user;
}
public String registPage() {
return "registPage";
}
public String findByName() throws IOException {
User existUser = userService.findByUsername(user.getUsername());
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
if(existUser != null){
response.getWriter().println("<font color=‘red‘>用户名已存在</font>");
}else{
response.getWriter().println("<font color=‘green‘>用户名可以使用</font>");
}
return NONE;
}
public String regist(){
userService.save(user);
return NONE;
}
}
标签:
原文地址:http://www.cnblogs.com/zzj123/p/4679362.html