如何在javascript中获取请求转发后的request对象传递的数据
2016-01-04 10:11
821 查看
下面的例子:在 index.jsp 页面通过
request.setAttribute("param","nihao"); 来给变量param赋值,
并通过 <jsp:forward page="deal.jsp"/>将页面请求转发到deal.jsp,
然后在deal.jsp页面单击按钮,通过onclick事件调用show()方法,
show()方法的 var str="<%=request.getAttribute("param") %>"语句就是在javascript中通过jsp语句
获取request范围内的变量的值,
最后通过 document.getElementById("showText").value=str把值显示在文本框中
index.jsp:
.
.
.
<body>
<%
String str="param";
request.setAttribute("param","nihao");//保存执行结果
%>
<jsp:forward page="deal.jsp"/>
</body>
.
.
.
deal.jsp:
.
.
.
<head>
<script language="javascript">
function show(){
var str="<%=request.getAttribute("param") %>";
document.getElementById("showText").value=str;
}
</script>
</head>
<body>
<input type="button" value="Shot Me" onclick="show()">
<input type="text" id="showText"/>
</body>
.
.
.
request.setAttribute("param","nihao"); 来给变量param赋值,
并通过 <jsp:forward page="deal.jsp"/>将页面请求转发到deal.jsp,
然后在deal.jsp页面单击按钮,通过onclick事件调用show()方法,
show()方法的 var str="<%=request.getAttribute("param") %>"语句就是在javascript中通过jsp语句
获取request范围内的变量的值,
最后通过 document.getElementById("showText").value=str把值显示在文本框中
index.jsp:
.
.
.
<body>
<%
String str="param";
request.setAttribute("param","nihao");//保存执行结果
%>
<jsp:forward page="deal.jsp"/>
</body>
.
.
.
deal.jsp:
.
.
.
<head>
<script language="javascript">
function show(){
var str="<%=request.getAttribute("param") %>";
document.getElementById("showText").value=str;
}
</script>
</head>
<body>
<input type="button" value="Shot Me" onclick="show()">
<input type="text" id="showText"/>
</body>
.
.
.
相关文章推荐
- 学习javascript面向对象 javascript实现继承的方式
- JavaScript数组去重
- 常用js
- 利用d3.js绘制中国地图
- 学习javascript面向对象 掌握创建对象的9种方式
- javascript进击(四)HTML DOM
- 学习javascript面向对象 理解javascript对象
- js中的return
- 基于JavaScript实现移除(删除)数组中指定元素
- javaScript学习基础知识汇总
- js中this指什么
- 实例代码详解javascript实现窗口抖动及qq窗口抖动
- ext js alert
- html解析工具jsoup结合模版引擎FreeMarkers的简单实例
- javascript基础语法学习笔记
- 封装好的javascript前端分页插件pagination
- js控制精度的加减乘除:js浮点数计算问题
- js完整教程一 : 基本概念和数组操作
- 详解javascript的变量与标识符
- JavaScript 闭包环境非常奇特 - 相当于类与实例的关系?!