day25_Struts2学习笔记_01 (2)

关于struts.xml没有提示的问题
分析原因:没有找到对应的dtd约束文件。
解决办法:
a.开发时联网
b.开发时不能上网咋办呢?那就手动添加该约束文件,过程如下:



附上:上述的struts.xml和web.xml文件

struts.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">


<struts>

</struts>
web.xml文件(注意:新版本的区别)

if you are using struts2 version 2.5 you need to change from 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
to
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
是的,去掉了中间.ng文件空间名,原因是在整合xwork的时候,同时简化了不必要的包名空间。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee "
    id="WebApp_ID" version="3.1">

    <display-name>day25_00_struts2Template</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <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-list>
</web-app>
七、Struts2入门案例

  以下步骤是日后实际开发中经常重复的。

建立一个访问视图的.jsp文件

在struts.xml文件中配置

建立动作类和动作方法

结果视图页面

测试

小问题解决
上面的模板我们做好了,就可以复制使用该模班,注意:复制该模板后,必须要修改 Web Context Root的内容,否则部署的时候会报错(会出现跟模板名称一样的应用),步骤如下:在新项目上右键 --> Properties --> 在搜索框中输入 Web --> 在web Context Root 中 --> Config…,如下图所示:

八、第一个案例的执行过程

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wppdpj.html