码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2保存数据

时间:2015-07-27 10:41:43      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

 

}

Struts2保存数据

标签:

原文地址:http://www.cnblogs.com/zzj123/p/4679362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!