XXX_ProductCRUD的项目结构与配置文件
Posted strugglinggirl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XXX_ProductCRUD的项目结构与配置文件相关的知识,希望对你有一定的参考价值。
MVC_ProductCRUD Hibernate_ProductCRUD
项目结构 项目结构
配置文件web.xml
配置文件Product.hbm.xml
配置文件hibernate.cfg.xml
MVC_ProductCRUD Struts_ProductCRUD
项目结构 项目结构
配置文件web.xml(Struct_ProductCRUD)
配置文件struts.xml
代码:web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" 3 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 4 5 <servlet> 6 <servlet-name>ProductListServlet</servlet-name> 7 <servlet-class>servlet.ProductListServlet</servlet-class> 8 </servlet> 9 <servlet-mapping> 10 <servlet-name>ProductListServlet</servlet-name> 11 <url-pattern>/listProduct</url-pattern> 12 </servlet-mapping> 13 14 <servlet> 15 <servlet-name>ProductEditServlet</servlet-name> 16 <servlet-class>servlet.ProductEditServlet</servlet-class> 17 </servlet> 18 <servlet-mapping> 19 <servlet-name>ProductEditServlet</servlet-name> 20 <url-pattern>/editProduct</url-pattern> 21 </servlet-mapping> 22 23 <servlet> 24 <servlet-name>ProductUpdateServlet</servlet-name> 25 <servlet-class>servlet.ProductUpdateServlet</servlet-class> 26 </servlet> 27 <servlet-mapping> 28 <servlet-name>ProductUpdateServlet</servlet-name> 29 <url-pattern>/updateProduct</url-pattern> 30 </servlet-mapping> 31 <servlet> 32 <servlet-name>ProductDeleteServlet</servlet-name> 33 <servlet-class>servlet.ProductDeleteServlet</servlet-class> 34 </servlet> 35 <servlet-mapping> 36 <servlet-name>ProductDeleteServlet</servlet-name> 37 <url-pattern>/deleteProduct</url-pattern> 38 </servlet-mapping> 39 <servlet> 40 <servlet-name>ProductAddServlet</servlet-name> 41 <servlet-class>servlet.ProductAddServlet</servlet-class> 42 </servlet> 43 <servlet-mapping> 44 <servlet-name>ProductAddServlet</servlet-name> 45 <url-pattern>/addProduct</url-pattern> 46 </servlet-mapping> 47 48 </web-app>
代码:hibernate.cfg.xml
1 <?xml version=‘1.0‘ encoding=‘utf-8‘?> 2 <!DOCTYPE hibernate-configuration PUBLIC 3 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 5 6 <hibernate-configuration> 7 8 <session-factory> 9 <!-- Database connection settings --> 10 <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 11 <property name="connection.url">jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8</property> 12 <property name="connection.username">root</property> 13 <property name="connection.password">admin</property> 14 <!-- SQL dialect --> 15 <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 16 <property name="current_session_context_class">thread</property> 17 <property name="show_sql">true</property> 18 <property name="hbm2ddl.auto">update</property> 19 <mapping resource="pojo/Product.hbm.xml" /> 20 </session-factory> 21 22 </hibernate-configuration>
代码:Product.hbm.xml
1 <?xml version="1.0"?> 2 <!DOCTYPE hibernate-mapping PUBLIC 3 "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 5 <hibernate-mapping package="pojo"> 6 <class name="Product" table="product_"> 7 <id name="id" column="id"> 8 <generator class="native"></generator> 9 </id> 10 <property name="name" /> 11 <property name="price" /> 12 </class> 13 </hibernate-mapping>
代码:web.xml(structs)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 3 <filter> 4 <filter-name>struts2</filter-name> 5 <filter-class> 6 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 7 </filter-class> 8 </filter> 9 <filter-mapping> 10 <filter-name>struts2</filter-name> 11 <url-pattern>/*</url-pattern> 12 <dispatcher>FORWARD</dispatcher> 13 <dispatcher>REQUEST</dispatcher> 14 </filter-mapping> 15 </web-app>
代码:struts.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 4 "http://struts.apache.org/dtds/struts-2.0.dtd"> 5 6 <struts> 7 <constant name="struts.i18n.encoding" value="UTF-8"></constant> 8 9 <package name="basicstruts" extends="struts-default"> 10 <action name="listProduct" class="action.ProductAction" 11 method="list"> 12 <result name="list">/product/list.jsp</result> 13 </action> 14 15 <action name="addProduct" class="action.ProductAction" 16 method="add"> 17 <result name="list" type="redirect">listProduct</result> 18 </action> 19 20 <action name="editProduct" class="action.ProductAction" 21 method="edit"> 22 <result name="edit" >/product/edit.jsp</result> 23 </action> 24 25 <action name="updateProduct" class="action.ProductAction" 26 method="update"> 27 <result name="list" type="redirect">listProduct</result> 28 </action> 29 30 <action name="deleteProduct" class="action.ProductAction" 31 method="delete"> 32 <result name="list" type="redirect">listProduct</result> 33 </action> 34 35 </package> 36 37 </struts>
以上是关于XXX_ProductCRUD的项目结构与配置文件的主要内容,如果未能解决你的问题,请参考以下文章