WEB开发网
开发学院软件开发Java Struts 2.1.6 精简实例系列教程(5):用户注册模块... 阅读

Struts 2.1.6 精简实例系列教程(5):用户注册模块(整合Jquery)

 2009-09-23 00:00:00 来源:WEB开发网   
核心提示: 好,你们来写我们的Action类RegisterAction.java,Struts 2.1.6 精简实例系列教程(5):用户注册模块(整合Jquery)(4),代码如下:packagecn.simple.action;importjava.io.IOException;importjavax.

好,你们来写我们的Action类RegisterAction.java,代码如下:

package cn.simple.action;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import cn.simple.manager.UserManager;
import cn.simple.pojo.User;
import com.opensymphony.xwork2.ActionSupport;
/** *//**
 * 处理用户注册的Action
 * @author rongxinhua
 *
 */
@Results({
    @Result(name = "success", location = "register-success.jsp", type="dispatcher"),
    @Result(name = "input", location = "registerform.jsp", type = "dispatcher")
})
public class RegisterAction extends ActionSupport {
    
    
    private User user;
    private String loginName1;
    
    public String execute() throws Exception {
        UserManager.insertUser(user);
        return SUCCESS;
    }
    
    /** *//**
     * 判断用户名是否存在(用于Ajax异步验证)
     * @throws Exception
     */
    public void isExistLoginName() throws Exception {
        if(loginName1.length() < 4 || loginName1.length() > 8){
            sendMsg("用户名长度应在4-8之间!");
        }else if(null != UserManager.selectUserByLoginName(loginName1)){
            sendMsg("用户名" + loginName1 + "已存在!");
        }else{
            sendMsg("success");
        }
        
    }
    
    /** *//**
     * 向客户端发送数据
     * @param content
     * @throws IOException
     */
    public void sendMsg(String content) throws IOException{
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(content);
    }
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    public String getLoginName1() {
        return loginName1;
    }
    public void setLoginName1(String loginName1) {
        this.loginName1 = loginName1;
    }
    
    
    
}

上一页  1 2 3 4 5  下一页

Tags:Struts 精简 实例

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接