SSH是Java web开发中常用的框架,本文将讲解SSH框架的搭建过程。这里使用的SSH分别为struts2.3.31,spring3.2.3以及hibernate4.3.10。
具体下载地址,百度即可。还有搭建SSH框架所需要的JDK,eclipse,tomcat这些软件,它们的安装方法这里就不介绍了。下面介绍具体的搭建步骤:
1.在eclipse中点击File->New->Dynamic Web Project,并输入项目名称SSHDemo,然后点击Finish。
2.配置Struts2,将Struts2需要的jar包复制到WebContent下的WEB-INF下的lib里面。必要的jar包如下:
3.在WEB-INF下创建web.xml文件,并编辑其内容如下:
S2SH
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.jsp
index.html
index.htm
4.在src下创建com.integration.action包,并在包中创建TestAction类,代码如下:
package com.integration.action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport{
public String execute() throws Exception{
return "success";
}
}
正如看到的一样,这个类什么也没做,直接返回success。
5.在src下创建struts.xml文件,编辑其内容如下:
/success.jsp
6.SSHDemo项目概览
其中index.jsp与success.jsp的代码分别如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here
Hello World!!
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here
访问成功!!
7.运行SSHDemo项目
在项目上右键点击Run As->Run on Server
在地址栏输入localhost:8080/SSHDemo/test
到此,Struts2配置完成。下一篇博客介绍Struts2与Spring的整合。