本文共 1688 字,大约阅读时间需要 5 分钟。
非常细致的步骤就不写了。只陈述一下基本的步骤以及要注意的事项。
1、新建Maven项目。(如果Eclipse已安装Maven插件,则“File->new->other->maven->maven Project“)。注意指定Archetype为maven-archetype-webapp。
2、打开POM.xml添加struts2的依赖。
3、配置web.xml。新建项目里,已自动生成web.xml在main/webapp/WEB-INF下。我们在<webapp></webapp>中间添加以下内容: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
4、配置struts.xml。新建文件struts.xml,注意放在src/main/resources下。内容如下:
5、编写loginAction类,注意不能放在src/main/resources下,因为这里的东西是资源,不会被当成代码来编译。要自己新建package。如src/main/java。添加后,设置项目的buildpath,添加src/main/java到Source。loginAction类:index.jsp test.jsp
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/