---恢复内容开始---
Jesery第一篇:实现Jesery前后台页面交互,Form表单提交,后台控制页面跳转
该项目中有实现的功能:
- Mybatis实现后台数据持久化
- Jersey页面数据提交
- 后台页面跳转
- 工厂设计模式根据beans.xml,获得对象
- JerseyClient测试
jar文件如下:
几个配置文件代码:
1.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://www.mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- properties配置 --> <!-- 这些属性都是可外部配置且可动态替换的, 既可以在典型的 Java 属性文件中配置, 亦可通过 properties 元素的子元素来传递。 --> <properties resource="db.properties"> <!-- 可在此属性中动态替换properties中的对应属性 --> <!-- <property name="" value=""/> --> </properties> <!-- <settings> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> --> <typeAliases > <typeAlias type="cn.nuist.chenlong.pojo.Ticket" alias="Ticket"/> <typeAlias type="cn.nuist.chenlong.pojo.User" alias="User"/> </typeAliases> <!-- setting属性会修改Mybatis在运行时的行为方式 --> <!-- typeAliases别名是为Java类型命名一个短的名字 --> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments> <mappers> <mapper resource="cn/nuist/chenlong/dao/ticketmapper.xml"/> <mapper resource="cn/nuist/chenlong/dao/usermapper.xml"/> </mappers> </configuration>
2.db.properties
driver=org.gjt.mm.mysql.Driver url=jdbc:mysql://localhost:3306/User?useUnicode=true&characterEncoding=utf8 username=root password=root
3.beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="UserDAO" className="cn.nuist.chenlong.dao.UserDAO"/> <bean id="TicketDAO" className="cn.nuist.chenlong.dao.TicketDAO"/> </beans>
4.web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>ticket</display-name> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>JerseyRest</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>cn.nuist.chenlong.resources</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.feature.Redirect</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>jersey.config.servlet.filter.forwardOn404</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>JerseyRest</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app>
具体项目源代码查看:https://github.com/JinGangRed/jersey.git