最近刚刚学习struct2,按照Struts 2权威指南--基于WebWork核心的MVC开发 上面的配置进行第一个struct例程学习。
纯手写的 呵呵。。。
1、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2、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="lee" extends="struts-default" >
<action name="Login" class="LoginAction">
<result name="error">error.jsp</result>
<result name="success">welcome.jsp</result>
</action>
</package>
</struts>
3、struts.properties
struts.devMode = true
struts.enable.DynamicMethodInvocation = false
4、lib 中包(struts2-blank-2.1.6 例程下面的 lib <此例程是struct2 自带 位于 apps目录下面>)
上面就是我刚刚开始配置文件,放到 tomcat 的 webapp文件夹下面
现在就说说容易出现问题
1、配置文件的拼写 我就是把struts.xml 写错了
2、在xml中尽量不要写空格,在goolge中看到一位老兄就是因为这个问题出现错误
3、lib下面尽量的包括struts2-blank-2.1.6下面的lib不要包括其他的,我就是因为包括了一个struts2-spring-plugin-2.1.6.jar 导致出错
4、不知道为什么我写的struts.properties总是不对,于是把他的内容放到struts.xml 中
在其中增加两句话
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
5、如果按照我上面配置的问题 基本可以运行了。
6、在jsp中action 中的名字就是 在struts 中配置的名字,在网上看到有还多原因是在jsp中action名字后面没有加.action.