jquery-validation

阅读更多
register.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
  
  <%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	%>  



  
    
    
    用户注册

	
	
	    
	
	
	
	
	
	
	
	
	
	
<%-- 	 --%>
	
	
  
  
  
    
    	

${message}

姓名
E-mail
密码
确认密码
看不清楚换一张



action:
package com.freemind.secondhand.action;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.freemind.secondhand.user.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 用户注册
 * 
 * @author zhangxiaolong
 *
 */
public class UserRegisterAction extends ActionSupport{
	private static final long serialVersionUID = -7359704415491782394L;

	private String name;
	
	private String pwd;
	
	private String rePwd;

	private String email;
	
	private UserService userService;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getRePwd() {
		return rePwd;
	}

	public void setRePwd(String rePwd) {
		this.rePwd = rePwd;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
   
	private InputStream inputStream;
	
	public InputStream getInputStream() {
		return inputStream;
	}
	
	/**
	 * 检查用户名是否存在
	 * 
	 * @return
	 */
	public String checkName()
	{
		Boolean isExits = true;
		if(userService.checkName(this.name) > 0)
		{
			 //return renderText("false");
			isExits = false;
			inputStream = new ByteArrayInputStream(isExits.toString().getBytes()); 
		}
		else
		{
			//return renderText("true");
			isExits = true;
			inputStream = new ByteArrayInputStream(isExits.toString().getBytes()); 
		}
		
		return SUCCESS;
	}
	
    /**
     * 注册
     * @return
     */
    public String register() 
    {
    	if(userService.register(name, pwd, email) > 0) {
  		   	return SUCCESS;
  	   	} else {
  	   		return ERROR;
  	   	}
    }
    
	protected String render(String text, String contentType) {
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType(contentType);
			response.getWriter().write(text);
		} catch (IOException e) {
		}
		return null;
	}

	/**
	 * 直接输出字符串.
	 */
	protected String renderText(String text) {
		return render(text, "text/plain;charset=UTF-8");
	}

}


struts.xml
 
	    	
               text/plain
                inputStream
            
	    

你可能感兴趣的:(jquery-validation)