今天第一次接触上structs1版本为structs1.3
老师给的项目名字为test,引用了strcts1中的org.apache.struts.action.Action;
在WEB-INF 中有文件夹lib,把structs1的jar包导入到这个文件夹下。
项目导入后报错:String cannot be resolved to a type.
1.配置structs1时,编写structs-config文件。
<structs-config>
<form-beans>
<form-bean name="loginForm" type="com.kqh.structsTest.LoginActionForm"/>
</form-beans>
<global-excetions/>
<global-forwards />
<action-mapping>
<action path="/login" type="com.kqh.structsTest.LoginActionForm" name="loginForm" scope="request">
<foward name="success" path="/login_success.jsp"/>
<forward name="error" path="/login_error.jsp" />
</action>
</action-mapping>
</structs-config>
然后出现了小红叉并且错误问题是The content of element type "action" must match "(icon?,display-
name?,description?,set-property*,exception*,forward*)".
最后发现竟然是forward 拼错了,不能被structs识别造成的。<img alt="尴尬" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/awkward.gif" />
</pre><pre name="code" class="html">
2.LoginActionForm loginForm = (LoginActionForm)form;
改行报错Cannot cast from ActionForm to LoginActionForm。
原因是LoginActionForm类还没有写完,没有extends Actionform类。所以转换也是不能的。
3.Missing configuration resource for path /WEB-INF/struts-config.xml
原因是struts-config.xml的文件名写错了。
4.No action config found for the specified url
原因是struts-config中的标签拼错了。
5.source cannot be null
struts-config:
<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.bjsxt.strutstest.LoginActionForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login" type="com.bjsxt.strutstest.LoginAction"
name="loginForm" scope="request">
<forward name="success" path="/login_success.jsp" />
<forward name="error" path="/login_error.jsp" />
</action>
</action-mappings>
</struts-config>
标红处是不一样的,上面的是bean的路径,而下面是servlet的路径。