参考代码如下:
<html>
<head>
<title>Test</title>
</head>
<body>
<form
action="/user/loginServlet.do"
method="post">
username:<input
name="username"
id="username"
type="text"/>
<br/>
password:<input
name="password"
id="password"
type="password"/>
<br/>
<input
type="submit"
name="btnLogin"
value="Login"/>
</form>
</body>
</html>
在servlet中的配置:
<web-app>
<!--
...
-->
<servlet>
<servlet-name>PageName</servlet-name>
<jsp-file>/success.html</jsp-file>
</servlet>
<!--
...
-->
<servlet-mapping>
<servlet-name>
PageName
</servlet-name>
<url-pattern>/user/*</url-pattern>
</servlet-mapping>
<!--
...
-->
</web-app>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<title> New Document </title>
<script type="text/javascript">
<!--
function goURL(){
var a = document.getElementById("month").value
var url
if(a == ""){
alert("请输入月份")
return
}
//注:最好再做下输入验证,比如说输入其它字符之类的
if(a == 4){
url = "a.html"
}else if(a == 5){
url = "b.html"
}
location.href = url
}
//-->
</script>
</head>
<body>
<input type="text" name="month" id="month"> <br/>
<input type="button" value="确定" onclick="goURL()">
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)