81,122
社区成员




import com.opensymphony.xwork2.*;
public class RegisterAction extends ActionSupport{
private String username;
private String password1;
private String password2;
public String doRegister() throws Exception{
return "abc";
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public String getPassword2() {
return password2;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<package name="user-manage" namespace="/usr" extends="struts-default">
<action name="register" class="com.csjl.infopub.struts2.usr.RegisterAction" method="doRegister">
<result name="input">/usr/register1.jsp</result>
<result name="success">/usr/register1.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
var cList =
[
{pId:110000,cId:110100,cName:"市辖区"},
{pId:110000,cId:110200,cName:"县"},
{pId:120000,cId:120100,cName:"市辖区"},
{pId:120000,cId:120200,cName:"县"}
];
var aList =
[
{cId:110100,aid:110107,aName:"石景山区"},
{cId:110100,aid:110108,aName:"海淀区"},
{cId:110100,aid:110109,aName:"门头沟区"},
{cId:110100,aid:110110,aName:"燕山区"},
{cId:110100,aid:110111,aName:"房山区"},
{cId:110100,aid:110112,aName:"通州区"},
{cId:110100,aid:110113,aName:"顺义区"},
{cId:110100,aid:110114,aName:"昌平区"},
{cId:110100,aid:110115,aName:"大兴区"},
{cId:110100,aid:110116,aName:"怀柔区"},
{cId:110100,aid:110117,aName:"平谷区"},
{cId:110200,aid:110221,aName:"昌平县"},
{cId:110200,aid:110222,aName:"顺义县"},
{cId:110200,aid:110223,aName:"通县"},
{cId:110200,aid:110224,aName:"大兴县"},
{cId:110200,aid:110225,aName:"房山县"},
{cId:110200,aid:110226,aName:"平谷县"},
{cId:110200,aid:110227,aName:"怀柔县"},
{cId:110200,aid:110228,aName:"密云县"},
{cId:110200,aid:110229,aName:"延庆县"},
{cId:120100,aid:120101,aName:"和平区"},
{cId:120100,aid:120102,aName:"河东区"},
{cId:120100,aid:120103,aName:"河西区"},
{cId:120100,aid:120104,aName:"南开区"},
{cId:120100,aid:120105,aName:"河北区"},
{cId:120100,aid:120106,aName:"红桥区"},
{cId:120100,aid:120107,aName:"塘沽区"},
{cId:120100,aid:120108,aName:"汉沽区"},
{cId:120100,aid:120109,aName:"大港区"},
{cId:120100,aid:120110,aName:"东丽区"},
{cId:120100,aid:120111,aName:"西青区"},
{cId:120100,aid:120112,aName:"津南区"},
{cId:120100,aid:120113,aName:"北辰区"},
{cId:120100,aid:120114,aName:"武清区"},
{cId:120100,aid:120115,aName:"宝坻区"},
{cId:120200,aid:120221,aName:"宁河县"},
{cId:120200,aid:120222,aName:"武清县"},
{cId:120200,aid:120223,aName:"静海县"},
{cId:120200,aid:120224,aName:"宝坻县"},
{cId:120200,aid:120225,aName:"蓟县"}
];
<%@page contentType="text/html" pageEncoding="GBK"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>JSP Page</title>
<script type="text/javascript" src="../js/area_json.js"></script>
<script type="text/javascript" src="../js/regular.js"></script>
<script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(
function(){
$("#txtPassword1").bind("blur",
function(){
var pwd1 = $("#txtPassword1").val();
if(pwd1.length < 6){
$("#tdPwd1").text("密码不能为空,且不能少于6个字符");
return;
}
$("#tdPwd1").text("");
var pwd2 = $("#txtPassword2").val();
if(pwd2 == ""){
$("#tdPwd2").text("请再次输入密码");
return;
}
if(pwd1 != pwd2){
$("#tdPwd2").text("两次输入的密码不相同");
return;
}
}
);
$("#txtPassword2").bind("blur",
function(){
var pwd1 = $("#txtPassword1").val();
var pwd2 = $("#txtPassword2").val();
if(pwd1 != pwd2){
$("#tdPwd2").text("两次输入的密码不相同");
return;
}
$("#tdPwd2").text("");
}
);
$("#txtEmail").bind("blur",
function(){
var email = $("#txtEmail").val();
if(email == ""){
$("#tdEmail").text("请填写您的email");
return;
}
if(!isEmail(email)){
$("#tdEmail").text("无效的email格式");
return;
}
$("#tdEmail").text("");
}
);
$("#txtUsername").bind("blur",
function(){
var username = $("#txtUsername").attr("value");
if(username.length <= 4){
$("#tdUsername").html("用户名不能小于5个字符");
return;
}
$("#tdUsername").html("");
$.ajax(
{
type:"get",
url:"./../ajax/user_exist.jsp",
data:"username=" + username,
success:function(msg){
msg = $.trim(msg);
if(msg == "exist"){
$("#tdUsername").html("用户名已经存在");
}else if(msg == "not exist"){
$("#tdUsername").html("此用户名可以使用");
}
}
}
);
}
);
}
);
function proinceChanged(){
var sP = document.getElementById("sProvince");
var sC = document.getElementById("sCity");
var provinceId = sP.value;
sC.options.length = 0;
for(var i = 0; i<cList.length; i++){
if(cList[i].pId != provinceId)
continue;
var option = document.createElement("option");
sC.appendChild(option);
option.value = cList[i].cId;
option.innerHTML = cList[i].cName;
}
cityChanged();
}
function cityChanged(){
var sC = document.getElementById("sCity");
var sA = document.getElementById("sArea");
var cId = sC.value;
sA.options.length = 0;
for(var i = 0; i<aList.length; i++){
if(aList[i].cId != cId)
continue;
var option = document.createElement("option");
sA.appendChild(option);
option.value = aList[i].aId;
option.innerHTML = aList[i].aName;
}
}
function onSubmit(){
var isOK = true;
var username = $("#txtUsername").val();
var pwd1 = $("#txtPassword1").val();
var pwd2 = $("#txtPassword2").val();
var email = $("#txtEmail").val();
var area = $("#sArea").val();
if(username.length <= 4){
$("#tdUsername").html("用户名不能少于5个字符");
$("#txtUsername").focus();
isOK = false;
}
if(pwd1.length < 6){
$("#tdPwd1").html("密码不能为空且不能少于6个字符");
$("#txtPassword1").focus();
isOK = false;
}
if(pwd2 != pwd1){
$("#tdPwd2").html("两次输入的密码不相同");
$("#txtPassword2").focus();
isOK = false;
}
if(email == ""){
$("#tdEmail").html("无效的email格式");
$("#txtEmail").focus();
isOK = false;
}else if(!isEmail(email)){
$("#tdEmail").html("无效的email格式");
$("#txtEmail").focus();
isOK = false;
}
if(area == null || area == ""){
$("#tdArea").html("请选择所在区域");
isOK = false;
}
return isOK;
}
</script>
</head>
<body>
<s:form name="registerForm" id="fForm" action="register" namespace="/usr" theme="simple" onsubmit="return onSubmit()">
<table width="800px" border="1" bordercolor="black" style="border-collapse: collapse">
<tr>
<td align="right">用户名</td>
<td><s:textfield name="username" id="txtUsername" autocomplete="off" /></td>
<td id="tdUsername">abc</td>
</tr>
<tr>
<td align="right">密码</td>
<td><s:password name="password1" id="txtPassword1" /></td>
<td id="tdPwd1"></td>
</tr>
<tr>
<td align="right">确认密码</td>
<td><s:password name="password2" id="txtPassword2" /></td>
<td id="tdPwd2"></td>
</tr>
<tr>
<td align="right">电子邮件</td>
<td><s:textfield name="email" id="txtEmail" autocomplete="off" /></td>
<td id="tdEmail"></td>
</tr>
<tr>
<td align="right">所在区域</td>
<td>
<select name="province" id="sProvince" onchange="proinceChanged()">
<s:set value="@com.csjl.infopub.db.cache.AreaCache@getInstance()" id="citySet" />
<s:iterator value="#citySet.provinces" status="st">
<option value="<s:property value='id' />"><s:property value="proName" /></option>
</s:iterator>
</select>省(直辖市)
<select name="city" id="sCity" onchange="cityChanged()"></select>市
<select name="area" id="sArea"></select>县区
</td>
<td id="tdArea"></td>
</tr>
<tr>
<td colspan="3" align="right">
<s:submit name="doRegister" title="注册" />
</td>
</tr>
</table>
</s:form>
</body>
</html>
<script type="text/javascript">
proinceChanged();
</script>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.csjl.infopub.struts2.usr;
import com.opensymphony.xwork2.*;
/**
*
* @author Administrator
*/
public class RegisterAction extends ActionSupport{
private String username;
private String password1;
private String password2;
private String email;
private int province;
private int city;
private int area;
public String doRegister() throws Exception{
return "abc";
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the password1
*/
public String getPassword1() {
return password1;
}
/**
* @param password1 the password1 to set
*/
public void setPassword1(String password1) {
this.password1 = password1;
}
/**
* @return the password2
*/
public String getPassword2() {
return password2;
}
/**
* @param password2 the password2 to set
*/
public void setPassword2(String password2) {
this.password2 = password2;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the province
*/
public int getProvince() {
return province;
}
/**
* @param province the province to set
*/
public void setProvince(int province) {
this.province = province;
}
/**
* @return the city
*/
public int getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(int city) {
this.city = city;
}
/**
* @return the area
*/
public int getArea() {
return area;
}
/**
* @param area the area to set
*/
public void setArea(int area) {
this.area = area;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<package name="user-manage" namespace="/usr" extends="struts-default">
<action name="register" class="com.csjl.infopub.struts2.usr.RegisterAction" method="doRegister">
<result name="input">/usr/register1.jsp</result>
<result name="success">/usr/register1.jsp</result>
</action>
</package>
</struts>
public String doRegister() throws Exception{
System.out.println("adc");
return "abc";
}
看有沒有輸出 要不你設置個断点你DEBUG下
return 的是你 STRUTS.XML ACTION里的 RESULT
看是不是其他验证的错误 默认是就转向 INPUT 的