当前位置: 代码迷 >> Web开发 >> JSP小疑点,本人电脑小白,求指教
  详细解决方案

JSP小疑点,本人电脑小白,求指教

热度:116   发布时间:2012-11-08 08:48:11.0
JSP小问题,本人电脑小白,求指教。
<%@ page language="java" pageEncoding="gb2312"%> 
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>dologin</title>
</head>

<body>
<%
  String userName=request.getParameter("username");//获取用户名
  session.setAttribute("name",name); //用户名写入session,显示留言时需要
  String passWord=request.getParameter("password");//获取口令
  if(userName.equals("huangzongshu")&&passWord.equals("123")) //用户名和密码正确
  response.sendRedirect("messageBoard.jsp"); //重定向到留言页面
  else
  response.sendError(500,"登陆错误,用户名或密码不正确!");
  %>
</body>
</html>

请问以上这段代码是否有错,为什么在登陆页面输入用户名和密码点击确定之后会出现404错误?

------解决方案--------------------
探讨
在IF前面先response.write userName和passWord 看看是什么。

------解决方案--------------------
检查action 路径 最好带上文根
<form action="dologin.jsp" method="post" name="form">
  相关解决方案