日期:2014-05-16  浏览次数:20930 次

Hibernate+struts+mysql+dwr(/*接受返回对象List)绑定下拉框
Hibernate+struts+mysql+dwr(/*接受返回对象List)绑定下拉框
引用
首先hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

	<session-factory>
		<property name="connection.username">root</property>
		<property name="connection.url">
			jdbc:mysql://localhost:3306/test
		</property>
		<property name="dialect">
			org.hibernate.dialect.MySQLDialect
		</property>
		<property name="myeclipse.connection.profile">dd</property>
		<property name="connection.driver_class">
			com.mysql.jdbc.Driver
		</property>
		<property name="show_sql">true</property>
		<mapping resource="com/accp/entity/Student.hbm.xml" />

	</session-factory>

</hibernate-configuration>

引用

接下来是web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
  </servlet>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>


引用
再者是dwr.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
	<allow>
		<convert match="com.accp.entity.Student" converter="bean">
		<param name="include" value="id,username,password,age" />
		</convert>
		<create creator="new" javascript="test">
			<param name="class" value="com.accp.test.test"/>
		<include method="selList"/> 
		</create>
	</allow>
	<signatures>
		<![CDATA[
		import java.util.List;
		import com.accp.entity.Student;
		import com.accp.test.test;
		test.selList(List<Student>);
		]]>
	</signatures>
</dwr>


引用
然后是测试类