您的位置:首页 > 编程语言 > Java开发

struts2学习一:搭建第一个struts2.5项目

2016-12-27 17:10 267 查看
在官网下载struts2.5.5的jar包,地址 http://struts.apache.org/download.cgi

使用tomcat7+1.7

打开eclipse,新建Dynamic Web Project





注意勾选Generate web.xml deployment descriptor



创建工程后,将下载到的相关jar包放入指定路径下,路径及具体jar文件参考下图



配置web.xml文件,简略如下图,注意红框内容,2.5版本与早期版本有所不同。



配置项目输出路径,项目上右键——属性——Java Build Path,设置下面的Default Output Folder为  {项目名称}/WebContent/WEB-INF/classes



在src路径下创建struts2.xml文件,并进行简单设置



设置项目属性——Server,选择相应的Tomcat。

设置Server



若Server Locations部分为灰色不能设置,则删除下面Server中tomcat下的项目并右键clean。

启动项目run on server,按照项目名称访问http://localhost:8080/struts2test/,报404错误

There is no Action mapped for namespace [/] and action name [] associated with context path [/struts2test].




需要在WebContent路径下创建index.html或其他在web.xml文件中设置的文件,如下

<welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

    <welcome-file>index.action</welcome-file>

  </welcome-file-list>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: