基于Eclipse搭建SSH框架:第一篇 配置struts2
2016-12-04 10:42
429 查看
SSH是Java web开发中常用的框架,本文将讲解SSH框架的搭建过程。这里使用的SSH分别为struts2.3.31,spring3.2.3以及hibernate4.3.10。
具体下载地址,百度即可。还有搭建SSH框架所需要的JDK,eclipse,tomcat这些软件,它们的安装方法这里就不介绍了。下面介绍具体的搭建步骤:
2.配置Struts2,将Struts2需要的jar包复制到WebContent下的WEB-INF下的lib里面。必要的jar包如下:
3.在WEB-INF下创建web.xml文件,并编辑其内容如下:
4.在src下创建com.integration.action包,并在包中创建TestAction类,代码如下:
5.在src下创建struts.xml文件,编辑其内容如下:
6.SSHDemo项目概览
其中index.jsp与success.jsp的代码分别如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello World!!
</body>
</html>
7.运行SSHDemo项目
在项目上右键点击Run As->Run on Server
在地址栏输入localhost:8080/SSHDemo/test
到此,Struts2配置完成。下一篇博客介绍Struts2与Spring的整合。
具体下载地址,百度即可。还有搭建SSH框架所需要的JDK,eclipse,tomcat这些软件,它们的安装方法这里就不介绍了。下面介绍具体的搭建步骤:
一、在Eclipse中创建一个web项目并配置好Struts2
1.在eclipse中点击File->New->Dynamic Web Project,并输入项目名称SSHDemo,然后点击Finish。2.配置Struts2,将Struts2需要的jar包复制到WebContent下的WEB-INF下的lib里面。必要的jar包如下:
3.在WEB-INF下创建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" id="WebApp_ID" version="2.5"> <display-name>S2SH</display-name> <filter> <!-- Filter名字 --> <filter-name>struts2</filter-name> <!-- Filter入口 --> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <!-- Filter名字 --> <filter-name>struts2</filter-name> <!-- 截获的URL --> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> </web-app>
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文件,编辑其内容如下:
<?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.xml文件的根元素 --> <struts> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <!-- <constant name="struts.objectFactory" value="spring" /> --> <!-- 定义包 --> <package name="default" namespace="/" extends="struts-default"> <action name="test" class="com.integration.action.TestAction"> <result name="success">/success.jsp</result> </action> </package> </struts>
6.SSHDemo项目概览
其中index.jsp与success.jsp的代码分别如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello World!!
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> 访问成功!! </body> </html>
7.运行SSHDemo项目
在项目上右键点击Run As->Run on Server
在地址栏输入localhost:8080/SSHDemo/test
到此,Struts2配置完成。下一篇博客介绍Struts2与Spring的整合。
相关文章推荐
- 基于Eclipse搭建SSH框架:第二篇 struts2整合spring
- Hadoop伪分布配置与基于Eclipse开发环境搭建
- 基于 Eclipse + Tomcat 的 Java Servlet Web 开发环境搭建与配置
- Hadoop伪分布配置与基于Eclipse开发环境搭建
- Java之基于Eclipse搭建SSH框架(上)
- eclipse配置Struts2至Tomcat8.5 全过程搭建
- Hadoop伪分布配置与基于Eclipse开发环境搭建
- 基于Eclipse搭建SSH框架:第四篇 使用SSH开发一个小程序
- Java之基于Eclipse搭建SSH框架(上)
- spring3.0+struts2+hibernate3整个环境的搭建和基于junit4的spring测试框架,最新技术的ssh框架
- Eclipse基于注解方式搭建ssh框架
- 第一篇 PHP开发环境搭建以及多站点配置(基于windows 7系统)
- 基于Eclipse搭建SSH框架:第三篇 整合Hibernate
- 【基于SSH框架的个人博客系统01】Eclipse搭建SSH框架详细流程
- Java之基于Eclipse搭建SSH框架(下)
- 基于 Eclipse + Tomcat 的 Java Servlet Web 开发环境搭建与配置
- 在J2EE Eclipse上配置Mysql----SSH框架搭建1
- Java之基于Eclipse搭建SSH框架(下)
- 基于Eclipse搭建第一个Struts2项目
- 搭建SSH框架之配置Struts2