帮忙看一下这个ajax注册的错误,老大们 急啊

zhurx166 2008-11-03 07:33:12
register.jsp
<%@ page language="java" pageEncoding="utf-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html locale="true">

<script type="text/javascript">
var req;

function UserNameCheck()
{
var username = document.getElementById('username').value;

var url = "/user.do?user_name=" + escape(username);

if (window.XMLHttpRequest) {

req = new XMLHttpRequest();

}else if (window.ActiveXObject) {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

if(req){

req.open("GET", url, true);

req.onreadystatechange = callback;

req.send(null);

}

}

function callback() {

if (req.readyState == 4) {

if (req.status == 200) {

parseMessage();

// update the HTML DOM based on whether or not message is valid

}else{

alert ("Not able to retrieve description" + req.statusText);

}

}
else
{
document.getElementById("check_username").innerHTML = "正在验证用户名....";
}
}


function parseMessage() {

var xmlDoc = req.responseXML.documentElement;

var node = xmlDoc.getElementsByTagName('info');

document.getElementById('check_username').innerHTML = node[0].firstChild.nodeValue;


}


function Form_Submit()
{
if(regForm.username.value=="")
{
alert("用户名不能为空!");
return false;
}
else if(regForm.password.value=="")
{
alert("密码不能为空!");
return false;
}
else if(regForm.password.value!=regForm.repassword.value)
{
alert("两次输入的密码不一致!");
return false;
}
regForm.submit();
}

</script>
<head>
<html:base />

<title>register.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body> <html:form styleId="regForm" method="post" action="/user.do">
<table width="70%" border="1">
<tr align="center">
<td colspan="2">
用户注册
</td>
</tr>
<tr>
<td width="24%" align="center">
用户名:
</td>
<td width="76%">
<input name="username" type="text" id="username" onBlur="UserNameCheck()">
<span id="check_username"></span>
</td>
</tr>
<tr>
<td align="center">
密码:
</td>
<td>
<input name="password" type="password" id="password">

</td>
</tr>
<tr>
<td align="center">
重复密码:
</td>
<td>
<input name="repassword" type="password" id="repassword">

</td>
</tr>
<tr>
<td align="center">
email:
</td>
<td>
<input name="email" type="text" id="email">
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="button" name="Submit" value="按钮" onClick="Form_Submit()">
</td>
</tr>
</table>
</html:form>
</body>
</html:html>

-----------------------------------------------
UserAction.java
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package org.marriager.action;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.marriager.form.UserForm;

/**
* MyEclipse Struts
* Creation date: 11-03-2008
*
* XDoclet definition:
* @struts.action path="/user" name="userForm" scope="request" validate="true"
*/
public class UserAction extends Action {
/*
* Generated Methods
*/
public String[] usernameList;
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException {
UserForm userForm = (UserForm) form;
System.out.println("我的");
response.setContentType("text/xml;charset=UTF-8");

response.setHeader("Cache-Control", "no-cache");

String username = (String) request.getParameter("user_name");

String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

if (username.equals("") || username == null) {

xml +="<message><info>Username is required !</info></message>";
}else if(this.IsContain(username))
{
xml += "<message><info>用户名已注册!</info></message>";
}
else
{
xml += "<message><info>合法用户名!</info></message>";
}

response.getWriter().write(xml);
return null;
}

public void init(ServletConfig config) throws ServletException {
usernameList = new String[] { "Tom", "Jerry", "Brain" };
}

public boolean IsContain(String param) {
for (int i = 0; i < usernameList.length; i++) {
if (usernameList[i].equals(param)) {
return true;
} else
continue;
}

return false;
}
}



------------------------------------------------------
struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
<data-sources />
<form-beans >
<form-bean name="userForm" type="org.marriager.form.UserForm" />

</form-beans>

<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="userForm"
name="userForm"
path="/user"
scope="request"
type="org.marriager.action.UserAction" />

</action-mappings>

<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>


怎么AJAX就的调用不了user.do呢 帮忙看一下错误
...全文
154 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhurx166 2008-11-03
  • 打赏
  • 举报
回复
req.open("GET", url, true);
我用alert来测试了一下 能运行到这里
zhurx166 2008-11-03
  • 打赏
  • 举报
回复
没有
java__king 2008-11-03
  • 打赏
  • 举报
回复
up
zhxjcooler 2008-11-03
  • 打赏
  • 举报
回复
req.open("GET", url, true);
这句话确定有执行吗
lihan6415151528 2008-11-03
  • 打赏
  • 举报
回复
抱歉,只会dwr
zhurx166 2008-11-03
  • 打赏
  • 举报
回复
没有人帮忙一下吗
zhj92lxs 2008-11-03
  • 打赏
  • 举报
回复
有什么异常吗

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧