<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head> <script type="text/javascript" language="javascript">
function check(){
if(document.getElementById("name").value==""){
alert("用户名为空");
return false;
}else{
return true;
}
}
</script>
<body>
<h1>
</h1>
<h1>
添加用户
</h1>
<form name="form1" action="loginok.html" method="post"> 中文用户名:
<input id="name" type="text" name="adminUser.name" />
span> * 密码:
<input id="password" type="text" name="adminUser.password" />
span> *
城市:
<select name="adminUser.city">
<option value="0">
请选择
</option>
<option value="北京">
北京
</option>
<option value="上海">
上海
</option>
</select>
地址:
<input type="text" name="adminUser.address" />
<input type="submit" value="保存" onclick="check()" />
</form>
</body>
</html>我的项目是ssh,strut1.2的,所以name那里是用formbean绑定问题一:为什么我点击保存的时候,"用户名为空"弹出来,还是会跳到form表单指定的action呢?
问题二:弹出对话框后,点击对话框后,我刚选的城市下拉列表是北京,页面闪了一下又跳回到"请选择"了,怎么办才能让他保留刚才的选择?
问题三:就是帮忙写个验证,弹出信息也好,怎么样都好就是让用户一定要输入和选择城市才能通过。。
解决方案 »
- 各位大侠!!求救!!配置SSH1集成的时候出现错误!请求指教
- Tomcat出现错误!
- struts2 date日期转换的问题....求解
- 如何透彻学习spring和hibernate
- hibernate 的cascade和数据库上的cascade是否会有冲突
- -----------------ibatis取不到数据---------------
- 菜鸟问题,各位大虾能告诉我这个代码的主要思想机理我吗?在线等!新手 没什么分 ,拜托啦!
- 有关apache soap的配置
- 请问如何在JDOM中输出‘&’字符
- Spring的@requestBody报错415 (Unsupported Media Type)
- 求今天 本周 的mysql语句
- 在做ssh(struts1.2+hibernate3.1+spring2.0)配置时,我把action作为bean配置到applicationContext.x
<head>
</head> <script type="text/javascript" language="javascript">
function check(){
if(document.getElementById("name").value==""){
alert("用户名为空");
return false;
}else{
return true;
}
}
</script>
<body>
<h1>
</h1>
<h1>
添加用户
</h1>
<form name="form1" action="loginok.html" method="post" onsubmit="return check()"> 中文用户名:
<input id="name" type="text" name="adminUser.name" />
密码:
<input id="password" type="text" name="adminUser.password" />
城市:
<select name="adminUser.city">
<option value="0">
请选择
</option>
<option value="北京">
北京
</option>
<option value="上海">
上海
</option>
</select>
地址:
<input type="text" name="adminUser.address" />
<input type="submit" value="保存"/>
</form>
</body>
</html>用submit的话,就要在提交表单之前返回。要想用onclick的话把表单提交换成button类型的,在js中提交表单。下面方法:<html>
<head>
</head> <script type="text/javascript" language="javascript">
function check(){
if(document.getElementById("name").value==""){
alert("用户名为空");
return false;
}else{
document.form1.submit();
}
}
</script>
<body>
<h1>
</h1>
<h1>
添加用户
</h1>
<form name="form1" action="loginok.html" method="post"> 中文用户名:
<input id="name" type="text" name="adminUser.name" />
密码:
<input id="password" type="text" name="adminUser.password" />
城市:
<select name="adminUser.city">
<option value="0">
请选择
</option>
<option value="北京">
北京
</option>
<option value="上海">
上海
</option>
</select>
地址:
<input type="text" name="adminUser.address" />
<input type="button" value="保存" onclick="check()"/>
</form>
</body>
</html>