博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
maven下搭建struts2
阅读量:4079 次
发布时间:2019-05-25

本文共 1688 字,大约阅读时间需要 5 分钟。

非常细致的步骤就不写了。只陈述一下基本的步骤以及要注意的事项。

1、新建Maven项目。(如果Eclipse已安装Maven插件,则“File->new->other->maven->maven Project“)。注意指定Archetype为maven-archetype-webapp。

2、打开POM.xml添加struts2的依赖。

4.0.0
cn.sigangjun.architecture
struts2
war
0.0.1-SNAPSHOT
struts2 Maven Webapp
http://maven.apache.org
org.apache.struts
struts2-core
2.3.15.2
junit
junit
3.8.1
test
struts2
3、配置web.xml。新建项目里,已自动生成web.xml在main/webapp/WEB-INF下。我们在<webapp></webapp>中间添加以下内容:

[xhtml] 
  1. <filter>  
  2.         <filter-name>struts2</filter-name>  
  3.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher  
  4.         </filter-class>  
  5.     </filter>  
  6.     <filter-mapping>  
  7.         <filter-name>struts2</filter-name>  
  8.         <url-pattern>/*</url-pattern>  
  9.     </filter-mapping>  

4、配置struts.xml。新建文件struts.xml,注意放在src/main/resources下。内容如下:

index.jsp
test.jsp
5、编写loginAction类,注意不能放在src/main/resources下,因为这里的东西是资源,不会被当成代码来编译。要自己新建package。如src/main/java。添加后,设置项目的buildpath,添加src/main/java到Source。loginAction类:

public class loginAction {      public String login(){          return "success";      }  }
在src下边新建包cn.sigangjun.action,并在该包下新建TestAction类:

package cn.sigangjun.action;public class TestAction {	public String test() {		return "success";	}}

6、最后写一个index.jsp和test.jsp页面。注意放在webapp下。

 

项目启动后。访问localhost:8080/项目名/login就可以看到index.jsp页面的内容。

转载地址:http://idnni.baihongyu.com/

你可能感兴趣的文章
PostgreSQL代码分析,查询优化部分,process_duplicate_ors
查看>>
PostgreSQL代码分析,查询优化部分,canonicalize_qual
查看>>
PostgreSQL代码分析,查询优化部分,pull_ands()和pull_ors()
查看>>
IA32时钟周期的一些内容
查看>>
获得github工程中的一个文件夹的方法
查看>>
《PostgreSQL技术内幕:查询优化深度探索》养成记
查看>>
PostgreSQL查询优化器详解之逻辑优化篇
查看>>
STM32中assert_param的使用
查看>>
C语言中的 (void*)0 与 (void)0
查看>>
vu 是什么
查看>>
io口的作用
查看>>
IO口的作用
查看>>
UIView的使用setNeedsDisplay
查看>>
归档与解归档
查看>>
Window
查看>>
为什么button在设置标题时要用一个方法,而不像lable一样直接用一个属性
查看>>
字符串的截取
查看>>
2. Add Two Numbers
查看>>
17. Letter Combinations of a Phone Number (DFS, String)
查看>>
93. Restore IP Addresses (DFS, String)
查看>>