当前位置: 代码迷 >> Java Web开发 >> [求助]我的代码有灵异事件~哭~想了好久,大家来看看
  详细解决方案

[求助]我的代码有灵异事件~哭~想了好久,大家来看看

热度:412   发布时间:2007-01-26 21:50:00.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  

----------------解决方案--------------------------------------------------------
有什么问题吗?
if (struct.check_login(bean)) {
response.sendRedirect("/webmo/login_interface.jsp");
} else {
response.sendRedirect("/webmo/login_rollbace.jsp");
}
你这个判断成立不就直接跳走了吗!

我从来不用断点调试WEB项目,你可以用,后台输出的方法监视你的程序步骤!
----------------解决方案--------------------------------------------------------
是呀,判断完了直接就跳走了呀。在login_checkservlet 干嘛还要停一下。。
----------------解决方案--------------------------------------------------------
  相关解决方案