关于DWR中WebContextFactory的测试(学习中ing~~~~)
来源:互联网 发布:淘宝卖电影票货源 编辑:程序博客网 时间:2024/06/11 02:14
首先是第一个页面aa.jsp:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="STYLESHEET" type="text/css"
href="jspAgent/_css/headagent.css">
<script type='text/javascript' src='/tgtc/dwr/interface/tomajax.js'></script>
<script type='text/javascript' src='/tgtc/dwr/engine.js'></script>
<script type='text/javascript' src='/tgtc/dwr/util.js'></script>
<script type='text/javascript'>
function call(data){
window.document.write(data);
}
</script>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<form method="get" action="bb.jsp"><input type="text" name="hxj"
value="nihao"> <input type="button" value="nihao"
onclick="javascript:tomajax.myage('hxj',call)"><br>
<input type="text" id="nn"></form>
</body>
</html>
ajax的java代码:
package hxj.tgtc.actions.dwr;
import javax.servlet.http.HttpServletRequest;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
public class Test_ajax {
public Test_ajax() {
}
public String myage(String name) {
WebContextFactory factory = new WebContextFactory();
WebContext context = factory.get();
HttpServletRequest httpServletRequest = context.getHttpServletRequest();
httpServletRequest.setAttribute("hh","Address is haoxiaojie");
try {
return context.forwardToString("/bb.jsp");
} catch (Exception e) {
System.out.println(e.getMessage());
return "bb.jsp";
}
}
} // end_all
跳转的页面bb.jsp:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
<script type='text/javascript' src='/tgtc/dwr/interface/tomajax.js'></script>
<script type='text/javascript' src='/tgtc/dwr/engine.js'></script>
<script type='text/javascript' src='/tgtc/dwr/util.js'></script>
<script type='text/javascript'>
function call(data){
$('nn').value = data;
}
</script>
</head>
<body>
<%
System.out.println(request.getAttribute("hh"));
System.out.println("号小姐");
%>
<input type="text" value="<%=request.getAttribute("hh") %>"><br>
<input type="text" value="123" id="nn"><br>
<input type="button" value="click" onclick="javascript:tomajax.myage('hxj',call);">
</body>
</html>
dwr.xml的配置:
<create creator="new" javascript="tomajax" scope="session">
<param name="class" value="hxj.tgtc.actions.dwr.Test_ajax"></param>
<include method="myage"/>
</create>
执行的结果:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="STYLESHEET" type="text/css"
href="jspAgent/_css/headagent.css">
<script type='text/javascript' src='/tgtc/dwr/interface/tomajax.js'></script>
<script type='text/javascript' src='/tgtc/dwr/engine.js'></script>
<script type='text/javascript' src='/tgtc/dwr/util.js'></script>
<script type='text/javascript'>
function call(data){
window.document.write(data);
}
</script>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<form method="get" action="bb.jsp"><input type="text" name="hxj"
value="nihao"> <input type="button" value="nihao"
onclick="javascript:tomajax.myage('hxj',call)"><br>
<input type="text" id="nn"></form>
</body>
</html>
ajax的java代码:
package hxj.tgtc.actions.dwr;
import javax.servlet.http.HttpServletRequest;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
public class Test_ajax {
public Test_ajax() {
}
public String myage(String name) {
WebContextFactory factory = new WebContextFactory();
WebContext context = factory.get();
HttpServletRequest httpServletRequest = context.getHttpServletRequest();
httpServletRequest.setAttribute("hh","Address is haoxiaojie");
try {
return context.forwardToString("/bb.jsp");
} catch (Exception e) {
System.out.println(e.getMessage());
return "bb.jsp";
}
}
} // end_all
跳转的页面bb.jsp:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
<script type='text/javascript' src='/tgtc/dwr/interface/tomajax.js'></script>
<script type='text/javascript' src='/tgtc/dwr/engine.js'></script>
<script type='text/javascript' src='/tgtc/dwr/util.js'></script>
<script type='text/javascript'>
function call(data){
$('nn').value = data;
}
</script>
</head>
<body>
<%
System.out.println(request.getAttribute("hh"));
System.out.println("号小姐");
%>
<input type="text" value="<%=request.getAttribute("hh") %>"><br>
<input type="text" value="123" id="nn"><br>
<input type="button" value="click" onclick="javascript:tomajax.myage('hxj',call);">
</body>
</html>
dwr.xml的配置:
<create creator="new" javascript="tomajax" scope="session">
<param name="class" value="hxj.tgtc.actions.dwr.Test_ajax"></param>
<include method="myage"/>
</create>
执行的结果:
- 关于DWR中WebContextFactory的测试(学习中ing~~~~)
- DWR框架中WebContext与WebContextFactory类
- dwr WebContextFactory 工厂模式
- dwr WebContextFactory 工厂模式
- DWR中函数测试
- Dwr WebContextFactory.get() null 问题
- 关于dwr的简单测试
- mtk学习中碰到的失误总结(不断更新ing)
- dwr通过WebContextFactory获取请求对象
- 数据可视化解决方案-学习中ing~
- 关于dwr中监听器类找不到问题
- Liferay中DWR的配置
- 项目中dwr的使用
- 关于学习DWR的一些注意要点
- 关于AJAX 框架DWR的学习
- Repast HPC Tutorial学习操作中出现的问题及解决办法(更新ing)
- C++ 细节与技巧 学习中更新ing
- 机器学习部分推荐论文列表(不断更新中ing...)
- 如何创建sqlserver 数据库(0002)
- reportmachine
- 解析xml之--DOM4J
- 服务器结构中的1U 2U 3U是什么意思?
- 如何解决ADO.NET访问Access数据库出现"操作必须使用一个可更新的查询"的问题
- 关于DWR中WebContextFactory的测试(学习中ing~~~~)
- 堆排序代码
- 10 tips for moving from programmer to entrepreneur
- 写代码,有点厌厌的!
- 网线制作方法
- 介绍防火墙NAT
- SQL中有用的函数和语句
- 橙子音频转换软件Orange Audio Converter v0.6.3版发布
- Q.931呼叫信令