dwr 调用 java 后台方法 在线求助 在线等 求大神帮忙

午夜忄 2014-05-08 01:28:03
页面有一个 input 和一个按钮 ; 想要在 点击按钮时将 input当中的编号作为参数 调用java 的后台方法 ,大家帮忙看看我这哪里有错误的地方 应该怎么修改 谢谢

我的dwr.xml:
<!DOCTYPE dwr PUBLIC 
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd ">
<dwr>
<allow>

<create creator="new" javascript="CityMatch">
<param name="class" value="entity.CityMatch" />
</create>

<create creator="new" javascript="CityMatchDao">
<param name="class" value="dao.CityMatchDao" />
</create>

<create creator="new" javascript="CityMatchDaoImpl">
<param name="class" value="dao.impl.CityMatchDaoImpl" />
<include method="getCityMatch" />
</create>

</allow>
</dwr>


我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>MyHtml.html</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>

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

</web-app>


java 实体类:
package entity;

/**
* 落地码实体类
* @author 杜文俊
*/

public class CityMatch {

private String cityId;
private String name;
private String long_min;
private String long_max;
private String lat_min;
private String lat_max;

/** 下面是一堆 set、get 方法 */
}


java 接口:
package dao;

/**
* 落地码查询接口
* @author 杜文俊
*/
public interface CityMatchDao {

/**
* 落地码查询接口
* @param cityId
* @return List<CityMatch>
* @author 杜文俊
* @update 2014-5-6 下午1:25:15
*/
public List<CityMatch> getCityMatch(String cityId);
}


java 接口的实现类:
package dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import dao.CityMatchDao;
import entity.CityMatch;
import util.ConnectionUtil;

/**
* 落地码查询接口实现类
* @author 杜文俊
*/
public class CityMatchDaoImpl extends ConnectionUtil implements CityMatchDao {

//数据库连接配置是单独写出去的 这里直接拿来用即可
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;

@SuppressWarnings("static-access")
public List<CityMatch> getCityMatch(String cityId){

List<CityMatch> cityMatchList = new ArrayList<CityMatch>();
String sql = "select * from CITY_MATCH where CITY_ID = " + cityId;

try {
con = this.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery(sql);

while(rs.next()){
CityMatch cityMatch = new CityMatch();
cityMatch.setCityId(rs.getString("city_id"));
cityMatch.setName(rs.getString("name"));
cityMatch.setLong_min(rs.getString("long_min"));
cityMatch.setLong_max(rs.getString("long_max"));
cityMatch.setLat_min(rs.getString("lat_min"));
cityMatch.setLat_max(rs.getString("lat_max"));
cityMatchList.add(cityMatch);
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeResultSet(rs);
this.closeStatement(stmt);
this.closeConn(con);
}

return cityMatchList;
}

}


我的 html:
<!DOCTYPE html>
<html>
<head>
<title>the test page</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type='text/javascript' src='/ZTWeb/dwr/interface/CityMatchDaoImpl.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/interface/CityMatchDao.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/interface/CityMatch.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/engine.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/util.js'></script>

<script language="javascript">
function callTestCityMatch(){
alert("45600000");

CityMatchDaoImpl.getCityMatch("152224");

}

</script>
</head>

<body>
the test form
</br>
<form action="post">
<table border=1>
<tr>
<td colspan="3">传递参数:<input id="resid" type="text" value="" /></td>
<td colspan="3"><input type="button" value=" 查 询 " onclick /></td>
</tr>
<tr>
<td>编号</td>
<td>名称</td>
<td>最小经度</td>
<td>最大经度</td>
<td>最小纬度</td>
<td>最大纬度</td>
</tr>
<tr>
<td>a</td>
<td>a</td>
<td>a</td>
<td>a</td>
<td>a</td>
<td>a<input type="button" value="aaa" name="button3"
onclick="test('012345')"></td>
</tr>
</table>
</form>
</body>
</html>


刚接触dwr 望大家帮忙更正 谢谢
...全文
209 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
午夜忄 2014-05-08
  • 打赏
  • 举报
回复
写成function的方法也拿不到 我这里贴错了 不管这个的事 看看其他有没有什么错误
jsdf2008 2014-05-08
  • 打赏
  • 举报
回复
引用 楼主 u010011052 的回复:
页面有一个 input 和一个按钮 ; 想要在 点击按钮时将 input当中的编号作为参数 调用java 的后台方法 ,大家帮忙看看我这哪里有错误的地方 应该怎么修改 谢谢 我的dwr.xml:
<!DOCTYPE dwr PUBLIC 
	"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" 
	"http://www.getahead.ltd.uk/dwr/dwr10.dtd ">
<dwr>
	<allow>
	
		<create creator="new" javascript="CityMatch">
			<param name="class" value="entity.CityMatch" />
		</create>
		
		<create creator="new" javascript="CityMatchDao">
			<param name="class" value="dao.CityMatchDao" />
		</create>
		
		<create creator="new" javascript="CityMatchDaoImpl">
			<param name="class" value="dao.impl.CityMatchDaoImpl" />
			<include method="getCityMatch" />
		</create>
		
	</allow>
</dwr>
我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
	<display-name></display-name>
	<welcome-file-list>
		<welcome-file>MyHtml.html</welcome-file>
	</welcome-file-list>

	<servlet>
		<servlet-name>dwr-invoker</servlet-name>
		<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
		<init-param>
			<param-name>debug</param-name>
			<param-value>true</param-value>
		</init-param>
	</servlet>

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

</web-app>
java 实体类:
package entity;

/**
 * 落地码实体类
 * @author 杜文俊
 */

public class CityMatch {

	private String cityId;
	private String name;
	private String long_min;
	private String long_max;
	private String lat_min;
	private String lat_max;

	/** 下面是一堆 set、get 方法 */
}
java 接口:
package dao;

/**
 * 落地码查询接口
 * @author 杜文俊
 */
public interface CityMatchDao {
	
	/**
	 * 落地码查询接口
	 * @param cityId
	 * @return List<CityMatch>
	 * @author 杜文俊
	 * @update 2014-5-6 下午1:25:15
	 */
	public List<CityMatch> getCityMatch(String cityId);
}
java 接口的实现类:
package dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import dao.CityMatchDao;
import entity.CityMatch;
import util.ConnectionUtil;

/**
 * 落地码查询接口实现类
 * @author 杜文俊
 */
public class CityMatchDaoImpl extends ConnectionUtil implements CityMatchDao {
	
	//数据库连接配置是单独写出去的 这里直接拿来用即可
	private Connection con = null;
	private Statement stmt = null;
	private ResultSet rs = null;
	
	@SuppressWarnings("static-access")
	public List<CityMatch> getCityMatch(String cityId){
		
		List<CityMatch> cityMatchList = new ArrayList<CityMatch>();
		String sql = "select * from CITY_MATCH where CITY_ID = " + cityId;
		
		try {
			con = this.getConnection();
			stmt = con.createStatement();
			rs = stmt.executeQuery(sql);
			
			while(rs.next()){
				CityMatch cityMatch = new CityMatch();
				cityMatch.setCityId(rs.getString("city_id"));
				cityMatch.setName(rs.getString("name"));
				cityMatch.setLong_min(rs.getString("long_min"));
				cityMatch.setLong_max(rs.getString("long_max"));
				cityMatch.setLat_min(rs.getString("lat_min"));
				cityMatch.setLat_max(rs.getString("lat_max"));
				cityMatchList.add(cityMatch);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			this.closeResultSet(rs);
			this.closeStatement(stmt);
			this.closeConn(con);
		}
		
		return cityMatchList;
	}

}
我的 html:
<!DOCTYPE html>
<html>
<head>
<title>the test page</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type='text/javascript' src='/ZTWeb/dwr/interface/CityMatchDaoImpl.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/interface/CityMatchDao.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/interface/CityMatch.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/engine.js'></script>
<script type='text/javascript' src='/ZTWeb/dwr/util.js'></script>

<script language="javascript">
  		function callTestCityMatch(){
			alert("45600000");
  			
  			 CityMatchDaoImpl.getCityMatch("152224");
  			
  		}

	</script>
</head>

<body>
	the test form
	</br>
	<form action="post">
		<table border=1>
			<tr>
				<td colspan="3">传递参数:<input id="resid" type="text" value="" /></td>
				<td colspan="3"><input type="button" value=" 查 询 " onclick /></td>
			</tr>
			<tr>
				<td>编号</td>
				<td>名称</td>
				<td>最小经度</td>
				<td>最大经度</td>
				<td>最小纬度</td>
				<td>最大纬度</td>
			</tr>
			<tr>
				<td>a</td>
				<td>a</td>
				<td>a</td>
				<td>a</td>
				<td>a</td>
				<td>a<input type="button" value="aaa" name="button3"
					onclick="test('012345')"></td>
			</tr>
		</table>
	</form>
</body>
</html>
刚接触dwr 望大家帮忙更正 谢谢
你这个 onclick="test('012345')" 是指点击了执行test那个函数 你那test函数在哪里呢
tony4geek 2014-05-08
  • 打赏
  • 举报
回复
后台走没, js 测试方法看看

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧