jsp页面,点击提交,无任何反映,添加了提示信息,也没有任何提示

TuChief 2012-04-28 11:42:33
代码如下
#======addNews.jsp=========#
<%@ page language="java" import="java.util.*,cn.jmu.dao.*,cn.jmu.vo.*,cn.jmu.dao.impl.*,java.text.SimpleDateFormat" pageEncoding="gbk"%>
<html>
<head>
<title>添加新闻</title>
<link href="../css/table.css" rel="stylesheet" type="text/css" />
</head>

<body>
<script type="text/javascript">
function fun_check_form(){
if(document.form1.title.value==""){
alert("请输入新闻标题信息。");
return false;
}else if(document.form1.content.value==""){
alert("请输入新闻内容。");
return false;
}else{
return true;
}
}
</script>
<%
request.setCharacterEncoding("gbk");
String action = request.getParameter("add");
if (action != null && "add".equals(action)) {

String title = request.getParameter("title");
String content = request.getParameter("content");
NewsDAOImpl newsdao = new NewsDAOImpl();

News news = new News();
news.setTitle(title);
news.setContent(content);

boolean result = newsdao.insertNews(news);
if (result)
out.print("<script type='text/javascript'>alert('添加成功');location.replace('manageNews.jsp');</script>");
else
out.print("<script type='text/javascript'>alert('添加失败。');history.go(-1);</script>");
}
%>
<form action="addNews.jsp" method="post" class="form1" onSubmit="return fun_check_form()">
<table width="654" height="300" border="0" align="center">
<input type="hidden" name="action" value="add">
<tr>
<td height="30" colspan="2" align="center" bgcolor="#66FF66">
<font size="+1" style="font-weight: bold;">添加新闻</font></td>
</tr>
<tr>
<td width="94" height="38" align="center" bgcolor="#66FFCC"><b>新闻标题:</b></td>
<td width="544" bgcolor="#66FFCC">
<input name="title" type="text" id="title" size="77" /></td>
</tr>
<tr>
<td height="100" align="center" bgcolor="#66FFCC"><b>新闻内容:</b></td>
<td valign="top" bgcolor="#66FFCC">
<textarea name="content" id="content" cols="77" rows="20"></textarea></td>
</tr>
<tr>
<td height="25" colspan="2" align="center" bgcolor="#FFCCCC">
<input type="submit" name="submit" value="提交" />
    
<input type="reset" name="reset" value="重置" />
</td>
</tr>
</table>
</form>
</body>
</html>
...全文
428 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
TuChief 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

真不知道你的form1的对象在哪
<form action="addNews.jsp" method="post" class="form1" onSubmit="return fun_check_form()">


class or name???????
[/Quote]谢谢提醒,验证的是我写错了,改成name了,但是提交依然没反应
jillcomputer 2012-04-28
  • 打赏
  • 举报
回复
真不知道你的form1的对象在哪
<form action="addNews.jsp" method="post" class="form1" onSubmit="return fun_check_form()">


class or name???????
TuChief 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

你这 你这 你这 太远古了
[/Quote]
赶紧先帮我看看先,不知道为什么<input type="hidden" name="action" value="add">的值总是没办法一起提交到另一个页面上
chenhu87 2012-04-28
  • 打赏
  • 举报
回复
你这 你这 你这 太远古了
jmonian 2012-04-28
  • 打赏
  • 举报
回复


<form action="addNews.jsp" method="post" class="form1" onSubmit="return fun_check_form(this)">
jmonian 2012-04-28
  • 打赏
  • 举报
回复
<form action="addNews.jsp" method="post" class="form1" name="form1" onSubmit="return fun_check_form(form1)">


function fun_check_form(form1){
if(form1.title.value==""){
alert("请输入新闻标题信息。");
return false;
}

lgh1117 2012-04-28
  • 打赏
  • 举报
回复
你的代码这种提交表单方式没有什么异常和错误,是可以的,你可以把MyEclipse的验证放出来,验证一下你jsp的什么地方写错了
取直的时候,不要这么取
document.form1.content.value
这样不会跨浏览器,用document.getElementById("content").value来取值
TuChief 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

引用 3 楼 maxliu911 的回复:
你提交按钮上没有调用这个function啊,加上onclick="fun_check_form()"

就是<input type="submit" name="submit" value="提交" onclick="fun_check_form()" />
这个样子
[/Quote]验证的内容已经没问题了,问题是现在点击提交没有任何的反应
maxliu911 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 maxliu911 的回复:]
你提交按钮上没有调用这个function啊,加上onclick="fun_check_form()"
[/Quote]
就是<input type="submit" name="submit" value="提交" onclick="fun_check_form()" />
这个样子
maxliu911 2012-04-28
  • 打赏
  • 举报
回复
你提交按钮上没有调用这个function啊,加上onclick="fun_check_form()"

81,122

社区成员

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

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