「javadwr写法」java dwr
本篇文章给大家谈谈javadwr写法,以及java dwr对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java中的dwr框架怎么配置啊?主要用于什么地方啊?
配置很简单~主要用于直接调用java函数~!!!
首先需要用到dwr.jar
web.xml
?xml version="1.0" encoding="UTF-8"?
web-app version="2.4"
xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
"
display-nametest/display-name
servlet
servlet-namedwr/servlet-name
servlet-classorg.directwebremoting.servlet.DwrServlet/servlet-class
init-param
param-namedebug/param-name
param-valuetrue/param-value
/init-param
/servlet
servlet-mapping
servlet-namedwr/servlet-name
url-pattern/dwr/*/url-pattern
/servlet-mapping
welcome-file-list
welcome-fileindex.html/welcome-file
welcome-fileindex.htm/welcome-file
welcome-fileindex.jsp/welcome-file
welcome-filedefault.html/welcome-file
welcome-filedefault.htm/welcome-file
welcome-filedefault.jsp/welcome-file
/welcome-file-list
/web-app
dwr.xml
!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
""
dwr
allow
create javascript="UserDAOAjax" creator="new"
param name="class" value="org.thj.UserDAOAjax"/param
/create
create javascript="MyProjectDao" creator="new"
param name="class" value="org.thj.MyProjectDao"/param
/create
convert match="org.thj.User" converter="bean"/convert
/allow
/dwr
MyProjectDao.java
package org.thj;
import java.util.HashMap;
import java.util.Map;
public class MyProjectDao {
public String getName(String str){
String returnStr="";
returnStr="((("+str+"))))MyProjectDao.getName-return String";
return returnStr;
}
public Map getMap(){
MapString,String map=new HashMapString,String();
map.put("1", "v1");
map.put("2", "v2");
map.put("3", "v3");
return map;
}
}
my.jsp
%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
script type="text/javascript" src="dwr/engine.js"/script%--固定写法--%
script type="text/javascript" src="dwr/util.js"/script
script type="text/javascript" src="dwr/interface/MyProjectDao.js"/script%--由框架自动生成,文件名根据DWR文件而来--%
title测试/title
script type="text/javascript"
function validate()
{
var name = form1.username.value;
MyProjectDao.getName("黄东辉",callBack);
//UserDAOAjax.exitUser(name,show);%--exitUser()函数的返回值会赋给show()函数--%
}
function callBack(data){
alert("the return value is " + data);
}
function getMap(){
MyProjectDao.getMap(getMapCallBack);
}
function getMapCallBack(data){
for(var property in data){
alert("property:"+property);
alert(property+":"+data[property]);
}
}
/script
/head
body onload="validate()"
form action="#" name="form1"
table id="table1" border="0"
trtd 用户名:input type="text" name="username"//td/tr
trtd 密码:input type="text" name="password"/ /td/tr
trtd input type="button" value="点击" onclick="getMap();" / /td/tr
/table
/form
/body
/html
java语言使用dwr做文件上传并下载
dwr.xml
create javascript="fileUtils" creator="new"
param name="class" value="cn.xyurp.bggl.common.FileUtils"/param
/create
业务类
public class FileUtils {
/**
* 文件上传
*
* @return
*/
public String upload(FileTransfer fileTransfer, String fileName) {
try {
WebContext webContext = WebContextFactory.get();
// String realtivepath = webContext.getServletContext().getContextPath()
// + "/upload/";
String saveurl = webContext.getHttpServletRequest().getSession()
.getServletContext().getRealPath("/upload");
File file = new File(saveurl + "/" + fileName);
if (!file.exists()) {
file.mkdirs();
}
InputStream uploadFile = fileTransfer.getInputStream();
int available = uploadFile.available();
byte[] b = new byte[available];
FileOutputStream foutput = new FileOutputStream(file);
uploadFile.read(b);
foutput.write(b);
foutput.flush();
foutput.close();
uploadFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
return "";
}
}
html
// 注意 upload 只能用 dwr.util.getValue() 取值,
// 如果用 jquery $("#id") 等其他方式取的值作为参数, 上传将会上传失败
mce:script type="text/javascript" src="%=path%!--
/dwr/engine.js"
// --/mce:script
mce:script type="text/javascript" src="%=path%!--
/dwr/util.js"
// --/mce:script
mce:script type="text/javascript" src="%=path%!--
/dwr/interface/fileUtils.js"
// --/mce:script
--------------------------------
function addFile(){
// 注意 upload 只能用 dwr.util.getValue() 取值,
// 如果用 jquery $("#id") 等其他方式取的值作为参数, 上传将会上传失败
var uploadFile = dwr.util.getValue("uploadFile");
fileUtils.upload(uploadFile,'fileName.ext',function(data){
alert(data);
});
}
input type="file" name="uploadFile" id="uploadFile"/
input type="button" class="f_btn01" onclick="addFile()" value="上传"/
Java 怎样用DWR实现页面无刷新
IE进度条肯定会显示,另外想办法屏蔽吧,无刷新很简单,DWR提供了回调函数的接口,在回调函数中可以使用js动态改变数据
对于使用js只对数据进行刷新的操作应该了解吧!
下面例子是一个无刷新更改父页面信息的操作:
function update_hdsms() {
dwr.util.useLoadingMessage("正在提交...");
var formUpdate = dwr.util.getValues("formUpdate");
NewcpjhDWRJS.update(true,formUpdate, shows);//提交更新,shows为更新完成后的回调函数
}
function shows(data) {//回调函数中会有个更新完成后的返回值参数
if (data == "true") {//自己设置返回如果为true则进入刷新父页面数据
parent.selectser();//父页面中有selectser()的js函数对数据信息进行重刷新,只刷新数据部分
parent.win_tj_update.close();//这个没有必要知道了,这个是我关闭更新页面的方法
} else {
alert(data);
}
}
问题比较模糊,只能给你大概说说
关于javadwr写法和java dwr的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-08,除非注明,否则均为
原创文章,转载请注明出处。