软件151  王帅

1.增加web.xml

Maven项目最重要的配置文件是pom.xmlpom是“项目对象模型”的意思。现在pom.xml中有一个错误,提示缺少web.xml

 

展开目录srcmainwebapp,在里面新建文件夹“WEB-INF”,在“WEB-INF”中创建web.xml

 

web.xml内容如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

里面定义了主页名称,并将页面处理交给struts

 

2.webapp目录添加到Java Resources中统一管理

 

在项目上点击鼠标右键,选择Build Path”在“Source”选项卡中点“Add Folder”,选择如下图:

 

3.运行项目

选择菜单Run”—“Run Configurations”,设置如下图:

 

4.在浏览器中查看结果

地址栏输入http://localhost:9527/struts-test/”查看结果。

 

posted on 2017-06-27 14:29  世.外.人  阅读(161)  评论(0编辑  收藏  举报