【Web】Eclipse + Maven + Struts搭建服务器
一、环境
系统:Windows7
IDE:Eclipse-Kepler Service Release 2
使用插件:Maven(请预先在电脑上安装Maven)
二、搭建
在Eclipse中新建一个Maven工程:
选择Maven Project。
注意选择maven-archetype-web选项。Catalog处,点击右边的Configuration按钮,弹出对话框:
点击右边的Add remote Catalog,在Catalog file输入框中输入http://repo1.maven.org/maven2/archetype-catalog.xml,Description则随便输入(等于去一个名字)然后点击OK,继续Next。
在此处输入项目的group id和artifact id。点击Finish。此时项目的目录结构如下:
项目报错误,暂时可以不用管。下面继续配置。因为要用到Struts2,所以需要依赖很多相应的jar包,这就是使用Maven的目的,下面修改Maven的pom文件如下:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.amos</groupId> 5 <artifactId>struts2</artifactId> 6 <packaging>war</packaging> 7 <version>0.0.1-SNAPSHOT</version> 8 <name>struts2 Maven Webapp</name> 9 <url>http://maven.apache.org</url> 10 <dependencies> 11 <dependency> 12 <groupId>junit</groupId> 13 <artifactId>junit</artifactId> 14 <version>3.8.1</version> 15 <scope>test</scope> 16 </dependency> 17 <dependency> 18 <groupId>org.apache.struts</groupId> 19 <artifactId>struts2-core</artifactId> 20 <version>2.3.16</version> 21 </dependency> 22 <dependency> 23 <groupId>org.apache.commons</groupId> 24 <artifactId>commons-io</artifactId> 25 <version>1.3.2</version> 26 </dependency> 27 </dependencies> 28 <build> 29 <finalName>struts2</finalName> 30 </build> 31 </project>
View Code
增加了两个依赖的jar包。
配置web.xml如下:
1 <!DOCTYPE web-app PUBLIC 2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 3 "http://java.sun.com/dtd/web-app_2_3.dtd" > 4 <web-app> 5 <display-name>Archetype Created Web Application</display-name> 6 <filter> 7 <filter-name>struts2</filter-name> 8 <filter-class> 9 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 10 </filter-class> 11 </filter> 12 <filter-mapping> 13 <filter-name>struts2</filter-name> 14 <url-pattern>/*</url-pattern> 15 </filter-mapping> 16 </web-app>
View Code
这里拷贝的是struts-2.3.16-all.zip包里的apps/struts2-blank.war中的web.xml。也就是一个Struts2默认的web.xml的配置。
接着,我们来实现Action,在Java Resources目录下面新建一个源文件夹:
在该文件夹下面新建一个pacakge(com.android.displaymain),然后新建一个HelloAction,如下:
HelloAction代码如下:
1 package com.android.displaymain; 2 3 import com.opensymphony.xwork2.ActionSupport; 4 5 public class HelloAction extends ActionSupport{ 6 7 @Override 8 public String execute() throws Exception { 9 // TODO Auto-generated method stub 10 return SUCCESS; 11 } 12 }
View Code
在src/main/resources文件夹下面创建文件struts.xml文件:
在其中配置如下:
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" 4 "http://struts.apache.org/dtds/struts-2.3.dtd"> 5 6 <struts> 7 <package name="com.android.server" namespace="/" extends="struts-default" > 8 <action name="HelloAction" class="com.android.displaymain.HelloAction" method="execute"> 9 <result name="success">index.jsp</result> 10 </action> 11 </package> 12 </struts>
View Code
OK,现在右击项目,Run As ->Run on Server,此时弹出对话框,直接next,finish的,最后在Eclipse里面会弹出如下Tab:
这是因为我们没有指明Action,将链接改为:http://localhost:8080/display/HelloAction之后,即可得到如下输出:
到这里,整个项目就配置完成了。如果想要默认的情况下也能正确显示页面,需要我们配置一个默认的Action,将struts.xml文件改为如下样子:
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" 4 "http://struts.apache.org/dtds/struts-2.3.dtd"> 5 6 <struts> 7 <package name="com.android.server" namespace="/" extends="struts-default" > 8 <default-action-ref name="index"/> 9 10 <action name="index"> 11 <result>/index.jsp</result> <!-- index.htm为项目根目录的默认页面 --> 12 </action> 13 14 <action name="HelloAction" class="com.android.displaymain.HelloAction" method="execute"> 15 <result name="success">index.jsp</result> 16 </action> 17 </package> 18 </struts>
View Code
三、总结
这里主要讲述的是如何快速搭建一个可用的服务器,过程比较长,但是没有什么难度,需要一定的Maven基础和Struts基础,如果不会Maven,需要手动导入Jar包,比较麻烦,读者可以自行动手练习配置。
转载于:https://www.cnblogs.com/lqminn/p/3787950.html
【Web】Eclipse + Maven + Struts搭建服务器相关推荐
- Eclipse+Maven+Nexus+Tomcat远程搭建CentOS web server
Eclipse+Maven+Nexus+Tomcat远程搭建CentOS web server 工具的使用,参考了很多前辈的资料,虽然不是转载但也算不上原创,仅供自己和大家参考罢了. 笔者的本意是要在 ...
- java web前端模版,以Eclipse替核心搭建JAVA WEB开发环境(三)-模板项目Archetype
以Eclipse为核心搭建JAVA WEB开发环境(三)-模板项目Archetype 本篇介绍创建archetype,用于创建WEB项目的模板. 1.创建一个Dynamic Web Project. ...
- Eclipse+Maven+Struts2+Spring+Mybatis完整搭建
一.前言 公司框架是SSH,hibernate用的越来越少,做了几年后,也懒得用了,springjdbc玩到现在,maven,mybatis没用到一直都没去接触,感慨现在技术真是发展越来越快,有点落伍 ...
- java jetty eclipse_用Eclipse+Maven+Jetty构建Java Web开发环境(详细笔记)
(软件环境) 『系统』Windows 10 x64 『JAVA』JDK 1.8.0_91 『Eclipse』 Eclipse-oxygen 『Maven』 apache-maven-3.6.3 『Je ...
- eclipse + maven搭建SSM框架
eclipse + maven搭建SSM框架 0.系统环境 1)Windows 10 企业版 2)JDK 1.8.0_131 3)Eclipse Java EE IDE for Web Develop ...
- Eclipse利用Maven2搭建SpringMVC框架的Web工程
一.准备工作: 下载apache-maven--> 配置Maven_home -->下载Eclipse Maven插件 二.新建工程: 选择新建Maven Project arche ...
- 使用IntelliJ IDEA和Maven管理搭建+Web+Tomcat开发环境
使用IntelliJ IDEA和Maven管理搭建+Web+Tomcat开发环境 使用IntelliJ IDEA和Maven管理搭建+Web+Tomcat开发环境 前言:原来一直使用Eclipse,换 ...
- Eclipse+Maven创建web项目
有时候我们想用eclipse+maven创建web项目,怎么操作呢,下面我来给大家来分享一下方法 所需工具 已经安装了maven插件的elipse 步骤 1.打开eclipse,右键new--othe ...
- web.py搭建服务器
python搭建服务器 ------------------安装web.py------------------------ Windows10 python3.5 安装web.py问题 pip ...
最新文章
- WinCvs提示:import requires write access to the repository
- python获取命令行参数_Python获取命令行参数的正确方法,案例详解
- 【网络安全面试题】——文件目录穿越实现特权文件读取
- VS2010 IDE安装问题
- 百度地图API常规应用十功能
- zabbix 3.2 mysql_zabbix3.2的server和zabbix-agent2.2怎么监控MySQL的办法
- QQ音乐下载的flac文件转码mp3文件
- 【修身养性】那些看不见的教养
- 软件功能测试概论(课堂练习1)
- 外边距+内边距+边框详解
- 关于android6.0网络连接感叹号的问题
- XenApp发布IE为默认最大化
- 亚马逊 Sessions 与 Pageviews 有什么区别?
- [教程]在VS上使用scanf,解决scanf报错问题
- createjs初学-关于Ticker
- (14)主流WLAN标准及用途
- 豆豆趣事[2014年05月]
- oracle 取某一年1月1日的多种方法
- 常用的数字高程模型(DEM)数据介绍,附免费下载
- 成都计算机职高学校排名,成都计算机职高排名