客户端请求新页面的14种方法
来源:互联网 发布:mac允许安装未知来源 编辑:程序博客网 时间:2024/06/05 03:37
为了便于演示:先列出包结构:
现在以page1 跳转到page2 ,为例。
先看下page2.jsp内容:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
page2 <br>
<% out.print(request.getParameter("uid"));
%>
</body>
</html>
---------------------------------------------------------
接下来,最重要的看下page1的内容(包含4大类方法。14种具体方法):
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function fun1(){
window.location="page2.jsp";
}
function fun2(){
window.location="page2.jsp?uid=admin";
}
function fun3(){
window.open("page2.jsp?uid=admin");
}
function fun(){
var uid=document.getElementById("uid").value;
if(uid==""){
alert("请输入用户名");
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<!--第一大类: 使用超链接-->
<!-- 连接到page2 -->
<a href="page2.jsp">连接到page2</a><br>
<!-- 连接到page2,弹出新窗口 -->
<a href="page2.jsp " target="_blank">连接到page2</a><br>
<!-- 使用相对路径链接到page2 -->
<a href="./page2.jsp">连接到page2</a><br><!-- .表示当前所在文件夹 -->
<a href="../demo/page2.jsp">连接到page2</a><br><!-- 当前文件夹的上级文件夹 -->
<!-- 使用绝对路径链接到page2 -->
<a href="http://localhost:8080/fuxi/demo/page2.jsp">连接到page2</a><br>
<a href="<%=request.getContextPath()%>/demo/page2.jsp">连接到page2</a><br>
<!-- 连接到page2,同时传递参数 -->
<a href="page2.jsp?uid=admin">连接到page2</a><br>
<!--第二大类: 使用超链接+js-->
<!-- 使用js连接到page2 -->
<a href='javascript:window.location="page2.jsp";'>连接到page2</a><br>
<a href='javascript:fun1();'>连接到page2</a><br>
<!-- 使用js连接到page2,并传参 -->
<a href='javascript:fun2();'>连接到page2</a><br>
<!-- 使用js连接到page2,弹出新窗口,并传参 -->
<a href='javascript:fun3();'>连接到page2</a><br>
<!---第三大类:使用submit按钮提交表单来请求新页面->
<!-- submit提交表单 -->
<form action="page2.jsp" method="post">
<input type="text" name="uid">
<input type="submit" value="提交表单">
</form>
<!-- 验证后提交表单 -->
<form action="page2.jsp" method="post">
<input type="text" name="uid" id="uid"/>
<input type="submit" value="提交表单" onclick="return fun();">
</form>
<!-- 使用url方式提交数据 -->
<form action="page2.jsp?uid=admin" method="post">
<input type="submit" value="提交表单" >
</form>
<!-- 使用hidden方式提交数据 -->
<form action="page2.jsp" method="post">
<input type="hidden" name="uid" id="uid2" >
<input type="submit" value="提交表单">
<script type="text/javascript">
var u=document.getElementById("uid2").value="admin2";
</script>
</form>
<!--第四大类:使用html元素和javascript来提交表单-->
<!-- 使用button+js来提交表单 -->
<form id="form1" action="page2.jsp" method="post">
<input type="text" name="uid">
<input type="button" value="提交表单" onclick='document.getElementById("form1").submit();'>
</form>
<!-- <a>+js提交表单 -->
<form id="form2" action="page2.jsp" method="post">
<input type="text" name="uid">
<a href='javascript:document.getElementById("form2").submit();'>提交表单</a>
</form>
</body>
</html>
- 客户端请求新页面的14种方法
- 客户端请求新页面和提交数据的四种方式
- 打开新页面的几种方法(随时更新)
- .net几种打开新页面的方法
- javascript跳转到新页面的三种方法
- 禁止webbrowser打开新页面的方法
- JS打开新页面的方法
- JavaScript打开新页面的方法
- 打开新页面方法
- 简单的页面打开方法(新页面或同一页面)
- 在zencart中添加一个新页面的方法
- ASP.Net将用户导航到新页面的方法
- Wordpress下创建自定义新页面的方法
- 使用ajax请求,打开新页面
- 新页面的的建立
- 打开新页面的设定
- 新页面的CSS Reset
- zencart添加新页面的几种途径
- .NET开发必看资料53个+经典源码77个
- OpenCV基础篇之绘图及RNG随机数对象
- 菜鸟浅谈c++函数形参是引用,指针,普通参数
- java常用的设计模式
- OpenCV基础篇之像素访问
- 客户端请求新页面的14种方法
- OC基础语法的一些注意点
- 使用Pspice进行电路仿真
- 容器实现的查找最大序列
- OpenCV基础篇之图片叠加
- C#,ArcGIS Engine开发入门教程
- 第一天,向着黑马前进
- HDU - 4276 The Ghost Blows Light(spfa + 树上dp)
- fragment生命周期,总结很好。感谢博主