不能重定向是什么原因?

zhouzm 2003-09-15 12:10:37
我在Jbuilder7里面,写了一个登录的servlet程序时候,发现不能重定向到另一个网页,有人知道是什么原因吗?代码如下:
login.jsp
//----------------------
<script>
function loginSystem(){
if(document.formlogin.username.value == ""){
alert("请填写用户名!");
document.formlogin.username.focus();
return;
}
document.formlogin.action="./login_ok";
document.formlogin.submit();
}
</script>

<form name="formlogin" action="" method="post">
<td width="78" bgcolor="1544A1"><font color="#FFFFFF">社区登录 </font></td>
<td width="53" bgcolor="1544A1"><font color="#FFFFFF">用户名:</font></td>
<td width="110" valign="middle" bgcolor="1544A1"><input type="text" name="username" size="16" class="input"></td>
<td width="50" bgcolor="1544A1"><div align="center"><font color="#FFFFFF"> 密码:</font></div></td>
<td width="77" bgcolor="1544A1"><input type="password" name="userpwd" size="10" class="input"></td>
<td width="156" bgcolor="1544A1"><font color="#FFFFFF">  <a href="javascript:///" onclick="javascript: loginSystem()">登录</a>
<a href="./reg_before.jsp">注册</a> <a href="./lostpass.jsp">找回密码</a></font></td>
</form>
//-----login_ok(Servlet)-----
package richhowe;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import com.richhowe.tools.utils.StringUtils;
import com.richhowe.tools.Codify;
import com.richhowe.tools.Log;
import com.soten.connectionpool.PoolManager;
import com.richhowe.datebase.DBAccess;

public class Login_ok extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GB2312";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
HttpSession session = request.getSession(true);
String userName = StringUtils.Trim(Codify.toChineseStr(request.getParameter("username")));
String userPwd = StringUtils.Trim(Codify.toChineseStr(request.getParameter("userpwd")));
String sqlStr = "";
Connection conn = null;
ResultSet rs = null;
UserInfo userInfo = new UserInfo();
try{
sqlStr = "SELECT ID FROM USERINFO WHERE USERNAME='"
+ userName + "' AND USERPWD='" + userPwd + "'";
conn = PoolManager.getConnection();
rs = DBAccess.executeQuery(conn, sqlStr);
if(rs.next()){
userInfo.setID(rs.getInt("ID"));
userInfo.setUserName(userName);
userInfo.setUserPwd(userPwd);
session.setAttribute("userinfo", userInfo);
response.sendRedirect("/index.jsp");
}
else{
String errorMsg = "用户名不存在,请重新<a href='/login.jsp'>登录</a>|||密码不正确,请重新<a href='/login.jsp'>登录</a>";
response.sendRedirect("/error.jsp?errorMsg=" + errorMsg);
}
}
catch(Exception ex){
Log.writeLog("Login_OK: ERROR!");
}
}
//Clean up resources
public void destroy() {
}
}
断点经过response.sendRedirect("/index.jsp");可是页面没有跳转到index.jsp,在线等待!
...全文
187 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjdbf 2003-09-15
  • 打赏
  • 举报
回复
<form name="formlogin" action="" method="post"> action值要对应到Login_ok
kaibinsj 2003-09-15
  • 打赏
  • 举报
回复
实在不行就用js
window.location.href!
yaray 2003-09-15
  • 打赏
  • 举报
回复
多输出一些运行信息[ System.out.println(".....") ]
sammy791010 2003-09-15
  • 打赏
  • 举报
回复
是呀
dooluby 2003-09-15
  • 打赏
  • 举报
回复
你的<form name="formlogin" action="" method="post">里面的action是怎么写的???
如果是action="servlet/Login_ok"

那么,你的response.sendRedirect("/index.jsp");
就要写:response.sendRedirect("../index.jsp");
zhouzm 2003-09-15
  • 打赏
  • 举报
回复
没有出错信息,什么反应都没有!
kingssman 2003-09-15
  • 打赏
  • 举报
回复
又没有什么出错信息呀?还是什么反映都没有那种
zhouzm 2003-09-15
  • 打赏
  • 举报
回复
servlet已经在web.xml里面注册了,映射过来的就是login_ok,action我不是在javascrip里面指定了吗?我用response.sendRedirect("/index.jsp");就应该是指向到根目录下的index.jsp呀.

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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