1 Taglib是Struts的标记库
2 Struts2框架中核心组件就是Action、拦截器等,Struts2框架使用包来管理Action和拦截器等。每个包就是多个Action、多个拦截器、多个拦截器引用的集合。
写一个简单用户登录的项目,用struts框架。how to do it?
struts 项目
1 导入包
2 页面
3 web.XML 修改 添加过滤器,拦截器
4 配置 struts.xml 配置文件
ge There is no
Action mapped for namespace [/] and action name [Servlet] associated with context path [/DxmProject].
Could not find action or result
There is no Action mapped for namespace [/] and action name [Servlet] associated with context path [/DxmProject]. - [unknown location]
,导致错误的原因主要有两种。总结如下:
一、struts.xml文件错误。这种错误又分为以下几种:1,struts.xml文件名错误。一定要注意拼写问题;2,struts.xml文件放置路径错误。一定要将此文件放置在src目录下。编译成功后,要确认是否编译到classes目录中;3,struts.xml文件内容错误。下面给出一个正确的struts.xml文件以供参考。注意背景色部分。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="com.wanggc.struts2.sample.Struts2Action">
<result name="success">/jsp/result.jsp</result>
</action>
</package>
</struts>
反复确认之后,还是没找到错误
找度娘,好多种解决方案,木有一个可以解决我的问题的
最后发现是我的struts.xml是在src目录下,没有任何疑问
但是我的编译后classes文件默认却是在build目录下
不在WEB-INF下.......
这样它是找不到struts.xml文件的,报如上错误,也是情有可原的
最后,明确一点,struts.xm位于src下是为了编译后能找到struts配置文件,确保其在WEB-INF下才是根本!!!
更改eclipse web 项目默认编译输出路径:
eclipse中只能针对项目更改,因为其默认的是build目录下的,只能以项目更改:
项目右键 -》properties -》Java Build Path -》source -》Default output folder,选择你的路径,ok!
改为 web-inf! ok.