| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1027 人关注过本帖
标题:添加"检测用户名是否存在"的问题...
只看楼主 加入收藏
zq454660454
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-22
收藏
 问题点数:0 回复次数:9 
添加"检测用户名是否存在"的问题...

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.statepower.po.DepartmentPO"%>
<%@ page import="com.statepower.basic.Translate"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>中国电力科技研究所管理系统</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">
-->
<script type="text/javascript">
function checkadd(){
if(document.adduserinfo.realname.value == ""){
alert("请输入真实姓名!");
return false;
}
if(document.adduserinfo.username.value == ""){
alert("请输入用户名!");
return false;
}
if(document.adduserinfo.password.value == ""){
alert("请输入密码!");
return false;
}
if(document.adduserinfo.popedom.value == 0){
alert("请选择权限!");
return false;
}
if(document.adduserinfo.department.value= 0){
alert("请选择部门!");
return false;
}


return true;
}

</script>
</head>

<body>
<form action='./UserAddServlet' name='adduserinfo' method='post' onSubmit="return checkadd()">
<table border="1" align="center" >
<tr>
<td align="center"><img src="./image/logo.jpg"></td>
</tr>
<tr height="10">
<td align="center">
真实姓名:<input type="text" name="realname" value="" size="10" maxlength="10">
</td>
</tr>
<tr height="10">
<td align="center">
用&nbsp;&nbsp;户&nbsp;&nbsp;名:<input type="text" name="username" value="" size="10" maxlength="10">
</td>
</tr>
<tr height="10">
<td align="center">
密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" name="password" value="" size="12" maxlength="10">
</td>
</tr>
<tr height="10">
<td align="center">
权&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;限:<select name="popedom" style="width:100px">
       <option value="0">
=请选择=
</option>
<option value="1">
系统管理
</option>
<option value="2">
业务管理
</option>

<option value="3">
财务管理
</option>
<option value="4">
一般管理
</option>
</select>
</td>
</tr>
<tr height="10">
<td align="center">
<%
try {
Translate translate = new Translate();
List list = new ArrayList();
HttpSession se = request.getSession(true);
list = (List) se.getAttribute("alldepartment");

out.println("部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门:<select name='department' style='width:100px'>");
out.println("<option value='0'>=请选择=");
out.println("</option>");
/**输出list对象中封装的DepartmentPO对象的属性 */
for(int i=0;i<list.size();i++){
DepartmentPO temp = (DepartmentPO) list.get(i);

out.println("<option value="+translate.native2Unicode(temp.getDepartmentname())+">");
out.println(translate.native2Unicode(temp.getDepartmentname()));
out.println("</option>");

}
out.println("</select> ");
}catch(Exception e){}
%>
</td>
</tr>
<tr height="10">
<td align="center">
<input type="submit" value="增加" name="ok">&nbsp;&nbsp;
<input type="button" value="返回" name="back" onclick="window.location='setpopedom.jsp'">
</td>
</tr>
</table>
</form>
</body>
</html>



莪想在这个页面中.添加"检测用户名是否存在"的功能.怎么加...请大家多多帮忙,很急...今天莪会一直在线等的....

图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: 用户名 检测 
2007-09-22 09:38
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 
这个要用到AJAX了吧,让JS与后台的servlet相连,然后让servlet到后台数据库去查询然后返回你所想要的信息!

2007-09-22 10:53
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 

有个例子给你,也是和servlet通信,但不和数据库进行连接的,稍微改一下就行了!
JS
var xmlHttp;

function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}

function createQueryString(){
var firstName = document.getElementById("firstName").value;
var middleName = document.getElementById("middleName").value;
var birthday = document.getElementById("birthday").value;

var queryString = "firstName="+firstName+"&middleName="+middleName+"&birthday="+birthday;

return queryString;
}

function doRequestUsingGET(){
createXMLHttpRequest();

var queryString = "GetAndPostExample?";
queryString = queryString + createQueryString()+"&timeStamp="+new Date().getTime();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",queryString,true);
xmlHttp.send(null);
}

function doRequestUsingPOST() {
createXMLHttpRequest();

var url = "GetAndPostExample?timeStamp=" + new Date().getTime();
var queryString = createQueryString();

xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(queryString);
}

function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
parseResults();
}
}
}

function parseResults(){
var responseDiv = document.getElementById("serverResponse");
if(responseDiv.hasChildNodes()){
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText = document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}


2007-09-22 10:58
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 

servlet
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetAndPostExample extends HttpServlet {

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("456");
this.processRequest(request, response, "GET");
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("123");
this.processRequest(request, response, "POST");
}

protected void processRequest(HttpServletRequest request,
HttpServletResponse response, String method)
throws ServletException, IOException {
// TODO:Set content type of the response to text/xml
response.setContentType("text/xml");

// TODO:Get the user's input
String firstName = request.getParameter("firstName");
String middleName = request.getParameter("middleName");
String birthday = request.getParameter("birthday");

// TODO:Create the response text
String responseText = "Hello " + firstName + " " + middleName
+ ". Your birthday is " + birthday + "." + "[Method: " + method
+ "]";

// TODO:Write the response back to the browser
PrintWriter out = response.getWriter();
out.println(responseText);

// TODO:Close the writer
out.close();
}
}


2007-09-22 10:58
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 

html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sending Request Data Using GET and POST</title>

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

function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}

function createQueryString(){
var firstName = document.getElementById("firstName").value;
var middleName = document.getElementById("middleName").value;
var birthday = document.getElementById("birthday").value;

var queryString = "firstName="+firstName+"&middleName="+middleName+"&birthday="+birthday;

return queryString;
}

function doRequestUsingGET(){
createXMLHttpRequest();

var queryString = "GetAndPostExample?";
queryString = queryString + createQueryString()+"&timeStamp="+new Date().getTime();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",queryString,true);
xmlHttp.send(null);
}

function doRequestUsingPOST() {
createXMLHttpRequest();

var url = "GetAndPostExample?timeStamp=" + new Date().getTime();
var queryString = createQueryString();

xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(queryString);
}

function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
parseResults();
}
}
}

function parseResults(){
var responseDiv = document.getElementById("serverResponse");
if(responseDiv.hasChildNodes()){
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText = document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}

</script>
</head>

<body>
<h1>Enter your first name, middle name, and birthday:</h1>

<table>
<tbody>

<tr>
<td>First name:</td>
<td><input type="text" id="firstName" />
</tr>
<tr>
<td>Middle name:</td>
<td><input type="text" id="middleName" />
</tr>

<tr>
<td>Birthday:</td>
<td><input type="text" id="birthday" />
</tr>
</tbody>

</table>

<form action="#">
<input type="button" value="Send parameters using GET"
onclick="doRequestUsingGET();" />

<br />
<br />

<input type="button" value="Send parameters using POST"
onclick="doRequestUsingPOST();" />
</form>

<br />
<h2>Server Response:</h2>

<div id="serverResponse"></div>

</body>
</html>


2007-09-22 10:59
zq454660454
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-22
收藏
得分:0 

忽忽...可现在没时间去研究这个呢...不过还是要谢谢你了

2007-09-22 11:10
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 

var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}

function createQueryString(){
var firstName = document.getElementById("name").value;

var queryString = "name="+name;

return queryString;
}

function doRequestUsingGET(){
createXMLHttpRequest();

var queryString = "GetAndPostExample?";
queryString = queryString + createQueryString()+"&timeStamp="+new Date().getTime();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET",queryString,true);
xmlHttp.send(null);
}

function doRequestUsingPOST() {
createXMLHttpRequest();

var url = "GetAndPostExample?timeStamp=" + new Date().getTime();
var queryString = createQueryString();

xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(queryString);
}

function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
parseResults();
}
}
}

function parseResults(){
var responseDiv = document.getElementById("serverResponse");
if(responseDiv.hasChildNodes()){
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText = document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}

servlet用request.getParameter来得到参数
用PrintWriter out = response.getWriter();
out.println(responseText);返回从数据库里搞出来的东西就可以了


2007-09-22 11:40
zq454660454
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-22
收藏
得分:0 

ajax莪不懂,最好能在莪的代码上帮莪修改就好了

2007-09-22 14:36
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 
var firstName = document.getElementById("name").value;换成你标签的名字
GetAndPostExample是servlet的名字,只要套用就行了你要改就改这2个
上班中不能再发咯!

2007-09-22 14:57
xiaobohp
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2007-4-19
收藏
得分:0 

呵呵,人才到处都是啊,服!!


坚持, 只因不原放弃.
2007-09-25 20:17
快速回复:添加"检测用户名是否存在"的问题...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032464 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved