SSH学习笔记(一)

开发环境:1、MyEclipse 6.5

                    2、Tomcat 6.0

                    3、Struts2.0 + Hibernate3.2 + Spring2.0

一、编码前的操作

1、创建项目。在MyEclipse中新建一个Web Project,名为mytest,使用的是JavaEE 5 Library。项目实际地址为G:\workspace\ssh\mytest

2、将项目部署到tomcat。进入tomcat目录下的conf中(G:\apache-tomcat-6.0.30\conf),打开server.xml,在</Host>之上添加一行代码

<Context path="/mytest" docBase="G:\workspace\ssh\mytest\WebRoot" reloadable="true" />

添加到项目的映射

3、将tomcat与MyEclipse关联。在MyEclipse中,Window->Preferences->MyEclipse Enterprise Workbench->Servers->Tomcat->Tomcat 6.x,设定好相关Tomcat的目录。设定好目录后可以把MyEclipse自带的Tomcat禁用掉。在MyEclipse中,Window->Preferences->MyEclipse Enterprise Workbench->Servers->Integrated Sandbox->Myeclipse Tomcat6,点击disabled.

4、使用MyEclipse自带的导入功能来整合。步骤如后几点。

5、选中项目mytest,在MyEclipse中,myeclipse->Project Capabilities->Add Hibernate Capabilities,在弹出的对话框中选中Hibernate 3.2,"JAR Library Installation"选择"Copy checked Library ....." 。如果不选copy的话,部署到Tomcat时会有class not found 。

6、一步步next,当到选择database connection时,因为我们的小项目采用spring来管理,所以不选"Specify database connection detail?",同理,也不选"Create SessionFactory calss?"。一直到最后,就增加了项目的Hibernate支持。

7、接下来增加项目对Spring的支持。选中项目mytest,在MyEclipse中,myeclipse->Project Capabilities->Add Spring Capabilities,在弹出的对话框中选中Spring 2.0,选择前4个Library和Spring2.0 web library,,"JAR Library Installation"选择"Copy checked Library ....." 。

8、在接下来的弹窗中,不选"Enable AOP builder",将applicationContext.xml指定放在WEB-INF目录下,不选"Create Spring SessionFactory that reference"。一直到最后,就增加了项目的Spring支持。

9、手动添加对Structs的支持。使用的是structs 2.0.11。将(commons-logging-1.0.4.jar这个包spring带了,所以不用拷贝)freemarker-2.3.8.jar,ognl-2.6.11.jar,structs2-core-2.0.11.jar,structs2-spring-plugin-2.0.11.jar,xwork-2.0.4.jar拷贝到WEB-INF/lib/下。

10、在src目录下新建structs.xml文件,输入

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> </struts>

项目采用的是Spring来管理,相当于action只是在structs中申明。
11、在WEB-INF/web.xml添加structs的过滤器。在<welcome-file-list>之上添加

<filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

这样就添加了structs的支持。
12、在WEB-INF/web.xml中添加Spring的监听器。在</web-app>之上添加

<listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>

做完这个之后就可以启动tomcat看看,应该没有任何问题。


到现在为止,整个项目已经添加好了ssh的支持了。

转载于:https://www.cnblogs.com/moiyer/archive/2011/08/09/2316169.html

猜你喜欢

转载自blog.csdn.net/weixin_33757609/article/details/94693163
今日推荐