求助。。JSP不能进行表单验证;跳转到servlet名为Login,出现404错误

scott_like 2012-02-16 12:55:57
源代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
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>
<base href="<%=basePath%>">

<title>My JSP 'index.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">
-->

<!-- 验证输入用户名密码格式 -->
<script type="text/javascript">
function checkForm()
{
if(form1.userId.value == "")
{
alert("用户名不能为空");
form1.userId.focus();
return false;
}

if(form1.pwd.value == "")
{
alert("密码不能为空");
form1.userId.focus();
return false;
}

for(var i=0;i <3;i++)
{
if(i==2){alert("密码不能为空");return false;}
if(document.all.shengfen[i].checked){
reutrn true;
}

}
if(form1.userId.value.length<6||form1.userId.value.length>12)
{
alert("用户名输入长度错误,长度应介于6与12位之间");
form1.userId.focus();
return false;
}
if(form1.pwd.value.length<6||form1.pwd.value.length>12)
{
alert("密码输入长度错误,长度应介于6与12位之间");
form1.pwd.focus();
return false;
}
}
</script>


</head>

<body bgcolor="gray">
<h1 align="center"> 欢迎来到武科大教务管理系统</h1>
<hr>
<table width="99%" border="0">
<tr>
<td height="71" colspan="3"><h1 align="center">welcome</h1></td>
</tr>
<tr>
<td height="203"> </td>
<td width="42%">

<form action="./Login" method="post" name="form1">
<input type=hidden name="commitFlag" value="submit">
<table width="100%" border="0">
<tr>
<td width="66%" height="56" align="right"><span>用户名:</span></td>
<td width="54%"><input name="userId" type="text" class="text1" size="10" maxlength="16"></td>
</tr>
<tr>
<td height="47" align="right"><span >密码: </span></td>
<td><input name="pwd" type="password" class="text1" size="10" maxlength="16"></td>
</tr>
<tr>
<td width="46%" height="56" align="right"><span >身份:</span></td>
<td width="54%">
<input type="radio" name="shengfen" value="teacher" />教师<br>
<input type="radio" name="shengfen" value="student" />学生<br>
<input type="radio" name="shengfen" value="db" />管理员<br>
</td>
</tr>
<tr>
<td height="40" align="right"> </td>
<td align="left">
<input name="submintButton" type="submit" class="button1" value="确定" onclick="return checkForm()" >
 
<input name="reset" type="reset" class="button1" id="reset" value="取消">
</td>
</tr>

</table>
</form>
</td>
<td width="45%"> </td>
</tr>
<tr>
<td height="235"> </td>
<td> </td>
<td> </td>
</tr>

</table>

</body>
</html>
...全文
271 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
william0612 2012-02-17
  • 打赏
  • 举报
回复
form action="../Login"

  • 打赏
  • 举报
回复
检查你文件组织形式,检查你XML配置,再重新编译发布调试
lxpandsq 2012-02-17
  • 打赏
  • 举报
回复
form action="./Login"

两个会出问题的地方,
第一,你这个页面必须直接在项目的WebContent文件夹下。
第二,你login必须在xml中进行注册和配置路径。
chenjihong1989 2012-02-16
  • 打赏
  • 举报
回复
不能进行表达验证是应为你的js代码写错了
if(document.form1.userId.value == "")
{
alert("用户名不能为空");
form1.userId.focus();
return false;
}
你少了个document
至于你的跳转页面错误应该是你的action写得不对,你要跳转到那个servlet就应该是web.xml里面的那个servlet的url.
qingyinlancy 2012-02-16
  • 打赏
  • 举报
回复
404是请求资源路径出错
可能是web.xml中的<url-pattern>配置错了,跟表单的action=""不相符
xiaozhangnima 2012-02-16
  • 打赏
  • 举报
回复
另外你这是生成的?
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
不需要的话就手动删除了吧
xiaozhangnima 2012-02-16
  • 打赏
  • 举报
回复
404,是路径不对
../Login
fanyuna 2012-02-16
  • 打赏
  • 举报
回复
action="<%=basePath%>Login.do"
fanyuna 2012-02-16
  • 打赏
  • 举报
回复
action="<%=basePath%>Login.do"

把if(form1.userId.value == "")改成if(document.getElementsByName("userId")[0].value=="")以下类似

sylthas 2012-02-16
  • 打赏
  • 举报
回复
贴web.xml里的servlet配置
qq737604771 2012-02-16
  • 打赏
  • 举报
回复
<form action="./Login" method="post" name="form1">
改成<form action="<%=path%>/servlet/Login.do" method="post" name="form1">
前提是你的xml文件没改过 是自动生成的。
ouyangxiaokang6 2012-02-16
  • 打赏
  • 举报
回复
把./都去了,试试。
unbelievable2010 2012-02-16
  • 打赏
  • 举报
回复
也不贴出来web.xml跟servlet 但是你的from里面 把点去了~!你再试试
interceptor2012 2012-02-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fy_c_s_d_n 的回复:]
试试
action="<%=basePath%>./Login"
[/Quote]

action="<%=basePath%>Login"

慢慢试试!!
fy_c_s_d_n 2012-02-16
  • 打赏
  • 举报
回复
试试
action="<%=basePath%>./Login"
fy_c_s_d_n 2012-02-16
  • 打赏
  • 举报
回复
感觉是提交的action错误。

81,091

社区成员

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

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