当前位置: 代码迷 >> Java Web开发 >> [求助]为什么不会跳转!!
  详细解决方案

[求助]为什么不会跳转!!

热度:122   发布时间:2007-01-20 15:56:33.0
[求助]为什么不会跳转!!

写了个简单的登陆界面,代码如下。但点了提交没反应!:

index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<base href="<%=basePath%>">

<title>My JSP 'login.jsp' starting page</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">
-->

</head>

<body>
<form action="login.jsp" method = "POST"> </form>
<table align = "center">
<tr>
<td>用户名:
<td><input type = "text" name = "name">
<tr>
<td>密码:
<td><input type = "password" name = "password">
<tr>
<td><input type = "submit" name = "commit" value="登陆" align="center">
</table>
</body>
</html>



login.jsp代码:

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<base href="<%=basePath%>">

<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">
-->
</head>

<body>
<%
if(request.getParameter("name").equals("admin"))
if(request.getParameter("password").equals("admin"))
out.println("Welcome to here!");
else
out.println("密码错误");
else
out.println("该用户不存在");
%>
</body>
</html>
搜索更多相关主题的帖子: request  java  String  path  

----------------解决方案--------------------------------------------------------
<form action="login.jsp" method = "POST"> </form>


你这里错了,应该把文件域按钮等包含 在form里面,这样你点提交时,才会触发action
----------------解决方案--------------------------------------------------------
  
----------------解决方案--------------------------------------------------------
以后要小心哦

----------------解决方案--------------------------------------------------------

版主教训的是!!!


----------------解决方案--------------------------------------------------------


----------------解决方案--------------------------------------------------------
  相关解决方案