1. struts2.1与2.0的web.xml中的配置不太一样:
2.0中的是:org.apache.struts2.dispatcher.FilterDispatcher
2.1以及之后的是:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
当然2.1的也可以使用2.0中的配置,2.1中的“ng”就是“下一代”的意思
2. 设置struts2配置文件修改后自动跟新,无需重启服务器的配置:
<constant name="struts.devMode" value="false" />,模板文件中默认为false,改为true即可
表明是开发模式。
3. 关联源代码:
选中工程中引入的“jar文件”----右键---“properties”---java source attachment---location path中配置
"external folder"为"E:/下载/struts-2.3.1.2-all/struts-2.3.1.2/src/core/src/main/java"即可。
4. 关联java doc:
同关联源代码到properties---javadoc location--"file:/E:/下载/struts-2.3.1.2-all/struts-2.3.1.2/docs/"
如果在工程中某个地方有用到该"jar"中的类,可以直接在将鼠标放在该java语句上,然后"F1"即可看到该类的文档。
5. struts2中的action配置:
<action name="index">
<result>
/index.jsp
</result>
</action>
此时启动服务器我们直接访问的方式是工程名/index.action,在这里我们可以变为"工程名/index"也可以访问到,
struts2默认可以将".action"不写
6. struts2 编写struts.xml设置自动提示(如果没有的话):
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
" http://struts.apache.org/dtds/struts-2.0.dtd">
windows--preferences--xml catalog--add
key type:URI;key:http://struts.apache.org/dtds/struts-2.0.dtd
location:配置本地下载下来后的dtd文件所在地
7. struts2 package中的namespace的一点说明:默认为"",表示接受所有的action访问
一般我们的namespace设置的是"/",所以我们在输入访问地址的时候就是:
" http://localhost:8088/mytest/addUser.action"
这个"/"值的目录就是和"工程名mytest"后面的那个"/"对应;
如果设置namespace为"add"那么访问路径就应该是:
" http://localhost:8088/mytest/add/addUser.action"
错误的访问路径为" http://localhost:8088/mytest/addUser.action"
8. struts2的访问过程:
首先浏览器或客户端输入一个地址或发送一个请求,web容器根据地址或请求知道是用的哪个工程处理
,然后就会找到该工程的web.xml文件,然后就会找到web.xml中的struts2的filter,struts2的filter
会使用dofilter方法找到struts.xml中的namespace,然后是action,然后是result在就是将结果返回视图
本质就是将请求跟最后的结果分开(请求和视图分开)。
2.0中的是:org.apache.struts2.dispatcher.FilterDispatcher
2.1以及之后的是:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
当然2.1的也可以使用2.0中的配置,2.1中的“ng”就是“下一代”的意思
2. 设置struts2配置文件修改后自动跟新,无需重启服务器的配置:
<constant name="struts.devMode" value="false" />,模板文件中默认为false,改为true即可
表明是开发模式。
3. 关联源代码:
选中工程中引入的“jar文件”----右键---“properties”---java source attachment---location path中配置
"external folder"为"E:/下载/struts-2.3.1.2-all/struts-2.3.1.2/src/core/src/main/java"即可。
4. 关联java doc:
同关联源代码到properties---javadoc location--"file:/E:/下载/struts-2.3.1.2-all/struts-2.3.1.2/docs/"
如果在工程中某个地方有用到该"jar"中的类,可以直接在将鼠标放在该java语句上,然后"F1"即可看到该类的文档。
5. struts2中的action配置:
<action name="index">
<result>
/index.jsp
</result>
</action>
此时启动服务器我们直接访问的方式是工程名/index.action,在这里我们可以变为"工程名/index"也可以访问到,
struts2默认可以将".action"不写
6. struts2 编写struts.xml设置自动提示(如果没有的话):
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
" http://struts.apache.org/dtds/struts-2.0.dtd">
windows--preferences--xml catalog--add
key type:URI;key:http://struts.apache.org/dtds/struts-2.0.dtd
location:配置本地下载下来后的dtd文件所在地
7. struts2 package中的namespace的一点说明:默认为"",表示接受所有的action访问
一般我们的namespace设置的是"/",所以我们在输入访问地址的时候就是:
" http://localhost:8088/mytest/addUser.action"
这个"/"值的目录就是和"工程名mytest"后面的那个"/"对应;
如果设置namespace为"add"那么访问路径就应该是:
" http://localhost:8088/mytest/add/addUser.action"
错误的访问路径为" http://localhost:8088/mytest/addUser.action"
8. struts2的访问过程:
首先浏览器或客户端输入一个地址或发送一个请求,web容器根据地址或请求知道是用的哪个工程处理
,然后就会找到该工程的web.xml文件,然后就会找到web.xml中的struts2的filter,struts2的filter
会使用dofilter方法找到struts.xml中的namespace,然后是action,然后是result在就是将结果返回视图
本质就是将请求跟最后的结果分开(请求和视图分开)。