DWR简单实现改变一个修改一个按钮上面的值

今天写了一个小功能!整合了一下DWR 嘿嘿。

下面开始讲了

 

第一步整合DWR 也就是DWR.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<dwr>
<!-- AJAX技术具体实现 -->
<allow>
<convert match="dk.Help2VO" converter="bean"></convert>
<create creator="new" javascript="Help2" scope="session">
<param name="class" value="dk.Help2"/>
<include method="readValue"/>
<include method="writeProperties"/>
<include method="readProperties"/>
</create>
</allow>
</dwr>

第二步注册dwr 在web.xml里面

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


<servlet>
<servlet-name>dwrInvoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>classes</param-name>
<param-value>java.lang.Object</param-value>
</init-param>

<load-on-startup>10</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dwrInvoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

 

第三步:导入DWr.jar,common-logging.jar 这两个 jar包

 

第四步就开始写Hlep2.java

package dk;
import java.io.*;
import java.util.*;


public class Help2 {

public String readProperties(){
Properties props = new Properties();
Help2VO vo2 = new Help2VO();
String allDate ="";
String filePath = "F:\\util\\feedback.properties";
try{
props.load(new FileInputStream(filePath));
allDate = props.getProperty("btValue1")+","+props.getProperty("btValue2")+","+props.getProperty("btValue3")+","+props.getProperty("btValue4");
/* vo2.setBtValue1(props.getProperty("btValue1"));
vo2.setBtValue2(props.getProperty("btValue2"));
vo2.setBtValue3(props.getProperty("btValue3"));
vo2.setBtValue4(props.getProperty("btValue4"));*/
}catch(Exception e){
e.printStackTrace();
}
return allDate;
}

public void writeProperties(String name,String value){

System.out.println("name===="+name);
System.out.println("value===="+value);
Properties props = new Properties();
String filePath = "F:\\util\\feedback.properties";
try{
InputStream fis = new FileInputStream(filePath);
props.load(fis);
fis.close();
OutputStream fos = new FileOutputStream(filePath);
props.setProperty(name, value);
props.store(fos,name);
fos.flush();
fos.close();
}catch(IOException e){
e.printStackTrace();
}
}

/* public static void main(String[] args) {

Help2 p2 = new Help2();
System.out.println(p2.readProperties().getBtValue1());
System.out.println(p2.readProperties().getBtValue2());
System.out.println(p2.readProperties().getBtValue3());
System.out.println(p2.readProperties().getBtValue4());

}*/
}

 

这里的写法与上一篇的读写properties文件写法稍有不同,所以我这里使用的绝对路径,而不是在工程中了。

不过这写都是 问题不大的 稍微改变一下 输入输出流 就可以了!

 

hlep2VO.java

 

package dk;

public class Help2VO {

private String btValue1;
private String btValue2;
private String btValue3;
private String btValue4;

public String getBtValue1() {
return btValue1;
}

public void setBtValue1(String btValue1) {
this.btValue1 = btValue1;
}

public String getBtValue2() {
return btValue2;
}

public void setBtValue2(String btValue2) {
this.btValue2 = btValue2;
}

public String getBtValue3() {
return btValue3;
}

public void setBtValue3(String btValue3) {
this.btValue3 = btValue3;
}

public String getBtValue4() {
return btValue4;
}

public void setBtValue4(String btValue4) {
this.btValue4 = btValue4;
}

}

 

实际上页面上可以使用他 因为我返回的是String类型的 如果你返回的是VO类型的那么这里就需要了 在页面上需要使用JSON去获取vo中 的属性值

我这里开始是 试了一下 不过认为直接传String 然后切割 比较方便 所以就删除了

 

 

index.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type='text/javascript' src='/DwrChangeButtonValue/dwr/interface/Help2.js'></script>
<script type='text/javascript' src='/DwrChangeButtonValue/dwr/engine.js'></script>
<script type='text/javascript' src='/DwrChangeButtonValue//dwr/util.js'></script>
<script>

function test(){
document.getElementById("div1").style.display='block';
var t1 = document.getElementById("t1").value;
}

function b(){
alert("成功");
document.getElementById("div1").style.display='none';
document.getElementById("t2").value=document.getElementById("t1").value;
var name = "btValue1";
var value = document.getElementById("t1").value;
requestHelp(name,value);
}

function requestHelp(name,value){
alert(name+"---->"+value);
Help2.writeProperties(name,value,callback2);
}
function callback2(data){
}
</script>

<script type="text/javascript">
function getBtValue(){
Help2.readProperties(callback);
}

function callback(data){
var data1 = data.split(",");
alert(data1);
for(var i=0;i<data1.length;i++){
document.getElementById('t2').value=data1[0];
}
}
getBtValue();
</script>
</HEAD>

<BODY>
<input type="button" value="12" id='t2'>
<a href="javascript:test()">编辑</a>
<div id="div1" style="display: none">
<input type="text" id="t1">
<input type="button" οnclick="b()" value="提交">
</div>
<!--
<input type="button" οnclick="getBtValue()" value="测试" >
-->
</html>

 

 

效果:


 

点击编辑按钮


 

向文本框中输入内容:



点击提交


点击确定


 

最后确定

 



修改成功

然后 无论你怎么刷新页面 也是没有关系的 这里就解决了 需要改变按钮的值 而要在被迫在数据库创建一个字段来储存了!

 

 

 

ok 工程我也上传上来!嘿嘿 供大家下载!

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值