| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 707 人关注过本帖
标题:[求助]我的代码有灵异事件~哭~想了好久,大家来看看
取消只看楼主 加入收藏
え元元え
Rank: 1
等 级:新手上路
帖 子:103
专家分:0
注 册:2006-4-7
收藏
 问题点数:0 回复次数:0 
[求助]我的代码有灵异事件~哭~想了好久,大家来看看

代码竟然随意跳转
这是登录界面的代码
<%@page contentType="text/html; charset=GB2312"%>
<html>
<head>
<title>login_chat</title>
</head>
<body bgcolor="#ffffff">
<h1 align="center">
<font color="red">欢迎来到ぇ元元ぇ聊天室</font>
</h1>
<form method="post" action="/webmo/login_checkservlet">
<table align="center">
<tr>
<td>用户名:</td>
<td>
<input name="txtuser" type="text"/>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input name="txtpwd" type="password"/>
</td>
</tr>
<tr>
<td>
<input type="reset" value="重置"/>
</td>
<td>
<input type="submit" value="提交"/>
</td>
</tr>
<tr>
<td>
<a href="/webmo/register_user.jsp">立即注册</a>
</td>
<td>
<a href="/webmo/fetchPwd.jsp">找回密码</a>
</td>
</tr>
</table>
<hr/>
</form>
</body>
</html>

本来应该跳转到login_checkservlet,但是却跳过这个login_checkservlet 直接跳转到login_chatServlet,断点都不停的!!!昏~
气氛之于发了点火,下面是接下来的代码:Login_checkServlet

package chat_system;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Login_checkServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
request.setCharacterEncoding("gb2312");
//加载类,创建javabean
Structrue struct = new Structrue();
user_infoBean bean = new user_infoBean();

//接收用户信息
String username = request.getParameter("txtuser");
String pwd = request.getParameter("txtpwd");
//把用户信息写入bean
bean.setUser(username);
bean.setPwd(pwd);

//把当前用户名共享到会话里,留作以后来判断用
HttpSession ses = request.getSession();
ses.setAttribute("username", username);

if (struct.check_login(bean)) {
response.sendRedirect("/webmo/login_interface.jsp");
} else {
response.sendRedirect("/webmo/login_rollbace.jsp");
}

}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}

下面是login_interface的代码:

<%@page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>login_interface</title>
</head>
<body bgcolor="#ffffff">
<p align="center"> 欢迎来
${sessionScope.username} 进入元元聊天室~
</p>
<br/>
<p align="center">
<a href="/webmo/login_chatservlet?username="+${sessionScope.username}>点击此进入聊天室</a>
</p>
</body>
</html>


下面是login_chatServlet的代码:
package chat_system;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class login_chatServlet extends HttpServlet {

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
try {
String username = request.getParameter("username");
//用于储存聊天室聊天记录的ArrayList
Object obj = getServletContext().getAttribute("array_chat");
if (obj == null) { //避免空指针约束
obj = new Object();
ArrayList arraychat = new ArrayList();
getServletContext().setAttribute("array_chat", arraychat);
obj = arraychat;
}
ArrayList array_chat = (ArrayList) obj;
//进入聊天室的时候再聊天室发出消息
if( username != null )
{
array_chat.add("<font color='red'>系统提示:大家热烈欢迎<b>" + username +
"<b>进入聊天室</font>");
getServletContext().setAttribute("array_chat", array_chat); //把聊天记录的ArrayList共享到内存里
}
Object obj1 = getServletContext().getAttribute("array_list");
if (obj1 == null) { //避免空指针约束
obj1 = new Object();
ArrayList array_list = new ArrayList();
array_list.add("<b>成员列表<b>");
getServletContext().setAttribute("array_list", array_list);
obj1 = array_list;
}
ArrayList array_list = (ArrayList) obj1;
array_list.add(username);
getServletContext().setAttribute("array_list", array_list); //把成员资料保存到上下文共享中

response.sendRedirect("/webmo/chat_interface.jsp");
} catch (Exception ex) {
ex.printStackTrace();
}
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}


搜索更多相关主题的帖子: 灵异 代码 login head 
2007-01-26 21:50
快速回复:[求助]我的代码有灵异事件~哭~想了好久,大家来看看
数据加载中...
 
   



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

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