iteye_19968
iteye_19968
2009-03-24 12:10
浏览 841
已采纳

JavaScript 中form.submit()提交不响应问题


<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312"%>
<%@ page language="java" import="com.fredck.FCKeditor.*" %>
<%@ taglib uri="/WEB-INF/FCKeditor.tld" prefix="FCK" %>
<jsp:useBean id="sn" scope="page" class="com.bean.SystemBean" />
<jsp:useBean id="tb" scope="page" class="com.bean.TraveBean" />
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String dir=sn.getDir();
%>
<HTML><HEAD><TITLE>后台操作区</TITLE>
<LINK href="<%=basePath %><%=dir %>/images/Admin_Style.css" type=text/css rel=stylesheet>
<LINK href="<%=basePath %><%=dir %>/images/style.css" type=text/css rel=stylesheet>
<script type="text/javascript" src="<%=path %>FCKeditor/fckeditor.js"></script>
<STYLE type=text/css>
BODY {
MARGIN-LEFT: 0px; BACKGROUND-COLOR: #ffffff
}
.STYLE1 {color: #ECE9D8}
</STYLE>
</HEAD>
<script type="text/javascript">

function sub()
{

var form = document.getElementById('form1');
if(document.form1.name.value.replace(/\s+$|^\s+/g,"").length<=0||document.form1.age.value.replace(/\s+$|^\s+/g,"").length<=0
||document.form1.tel.value.replace(/\s+$|^\s+/g,"").length<=0||document.form1.remark.value.replace(/\s+$|^\s+/g,"").length<=0
||document.form1.address.value.replace(/\s+$|^\s+/g,"").length<=0)
{
alert("所有项目必须填写!");
return false;
}

form.submit();

}
</script>
<%
String message = (String)request.getAttribute("message");
if(message == null){
message = "";
}
if (!message.trim().equals("")){
out.println("<script language='javascript'>");
out.println("alert('"+message+"');");
out.println("</script>");
}
request.removeAttribute("message");
%>
<%
String username=(String)session.getAttribute("user");
if(username==null){
response.sendRedirect(path+"/error.jsp");
}
else{
String method=request.getParameter("method");
if(method==null){
method="addygzl";
}
//String wydz,String fx,String jzmj,String symj,String yzmc,String jg,String gzdw,String yb,
// String cwwz,String tczh,String wydz,String kssj,String jzsj,String bz
String name = "";

String age="";
String tel="";
String address="";
String remark="";
String id="";

    if(method.equals("upygzl")){
        id=request.getParameter("id").trim();
        List newsList=tb.getOneYg(Integer.parseInt(id));
        name=newsList.get(1).toString();
        age=newsList.get(3).toString();
        tel=newsList.get(4).toString();
        address=newsList.get(5).toString();
        remark=newsList.get(6).toString();  
    }       

%>
<BODY onload="document.form1.infoContent.value=document.form1.content.value" >
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align="left" vAlign=top >
<table width='100%' cellspacing='1' cellpadding='3' bgcolor='#CCCCCC' class="tablewidth">
<tr class="head">
<td colspan="2">

<%
if(method.trim().equals("addygzl")){
%>
添加员工信息
<%}else{%>
修改员工信息

<%} %>
</td>
</tr>
<form id="form1" name="form1" action="<%=basePath %>WyServlet" method="post" >
<tr bgcolor='#FFFFFF'>
<td width='30%'><div align="right">员工姓名:<input type="hidden" name="method" value="<%=method %>"> <input type="hidden" name="id" value="<%=id %>"></div></td>
<td ><input name="name" type="text" id="name" size="40" maxlength="100" value="<%=name %>"></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td width='30%'><div align="right">性&nbsp;&nbsp;&nbsp;&nbsp;别:</div></td>
<td ><input name="sex" type="radio" value="男" checked> 男 <input name="sex" type="radio" value="女"> 女 </td>
</tr>
<tr bgcolor='#FFFFFF'>
<td width='30%'><div align="right">员工年龄:</div></td>
<td ><input name="age" type="text" id="age" size="10" maxlength="100" value="<%=age %>"></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td width='30%'><div align="right">联系电话:</div></td>
<td ><input name="tel" type="text" id="tel" size="40" maxlength="100" value="<%=tel %>"></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td width='30%'><div align="right">联系地址:</div></td>
<td ><input name="address" type="text" id="address" size="40" maxlength="100" value="<%=address %>"></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td width='30%'><div align="right">备&nbsp;&nbsp;&nbsp;&nbsp;注:</div></td>
<td ><textarea name="remark" cols=40 rows=5><%=remark %></textarea></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td colspan="2" align="center">
<input class=mmcinb type='button' name='button' value='提交数据' onclick='sub()'>
</td>
</tr>

</table>
</form>
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
<%} %>
</HTML>


高呼 HELP~啊~~不知道为什么submit不提交,servlet类没有反映,注 web.xml里的相关信息配置准确无误。~毕业设计 着急
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • zhoujuan520
    zhoujuan520 2009-03-24 12:30
    已采纳

    着急就加我Q3990995

    点赞 评论
  • iteye_5372
    iteye_5372 2009-03-24 14:27

    看是否JS报错,可以先去掉上面的if试一下。在js报错的情况下下面的代码是不会执行的!

    点赞 评论

相关推荐