Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Struts 2默认页面_Java_Url_Struts2_Home Directory_Welcome File - Fatal编程技术网

Java Struts 2默认页面

Java Struts 2默认页面,java,url,struts2,home-directory,welcome-file,Java,Url,Struts2,Home Directory,Welcome File,我有一个使用struts 2的web应用程序,它可以通过在URL中输入动作来访问动作 localhost/project/index.action 但是如果不显式地输入它,它将不会重定向到这个默认操作 localhost/project/ 给出了错误 Error 404: SRVE0190E: File not found: {0} 我假设找不到该文件,因为我没有正确配置某些内容 有没有人能为我指出正确的方向,让我在Struts2中实现这种行为 这里的每个请求是我的struts.xml和w

我有一个使用struts 2的web应用程序,它可以通过在URL中输入动作来访问动作

localhost/project/index.action
但是如果不显式地输入它,它将不会重定向到这个默认操作

localhost/project/
给出了错误

Error 404: SRVE0190E: File not found: {0}
我假设找不到该文件,因为我没有正确配置某些内容

有没有人能为我指出正确的方向,让我在Struts2中实现这种行为

这里的每个请求是我的struts.xml和web.xml

web.xml


文档解析器
支柱准备
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
struts执行
org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter
网站
com.opensymphony.sitemesh.webapp.SiteMeshFilter
支柱准备
*.行动
/支柱/*
/
网站
*.行动
/支柱/*
/
struts执行
*.行动
/支柱/*
/
org.apache.struts2.dispatcher.ng.listener.StrutsListener
sitemesh自由标记
org.apache.struts2.sitemesh.FreemarkerDecoratorServlet
默认_编码
UTF-8
1.
场地网速度
org.apache.struts2.sitemesh.VelocityDecoratorServlet
默认_编码
UTF-8
1.
sitemesh自由标记
*.ftl
场地网速度
*.vm
index.jsp

Strust.xml




我发现

    <url-pattern>*.action</url-pattern>
    <url-pattern>/struts/*</url-pattern>
    <url-pattern>/</url-pattern>
*。操作
/支柱/*
/
正在阻止重定向到我的欢迎文件

模式

    <url-pattern>/*</url-pattern>
/*

修复了问题。

我有一个稍微不同的方法。不管是Struts 2还是java

只需在执行重定向的web应用程序的根目录中添加index.html

<meta http-equiv="refresh" content="0; url="http://localhost/home.action" />

对于作为defaut页面的操作,这对我很有用

<welcome-file-list>     
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/index.jsp</url-pattern>
</filter-mapping>

index.jsp
支柱2
/index.jsp
index.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:action name="welcome21" namespace="/" executeResult="true" />

struts.xml(jsp结果不是平铺)


/jsp/welcome2.jsp

这可以通过使用web.xml和/或struts.xml来实现。显示两个文件以获得更好的帮助刚刚添加了它们,我想知道这是否与标记有关?是否使用注释?尝试添加一个约定插件,它将处理这种情况。确实有效:)谢谢@RomanC
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:action name="welcome21" namespace="/" executeResult="true" />
<package name="default" namespace="/" extends="struts-default">
        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>


        <action name="welcome21" class="org.zzz.action.CommonAction" method="welcome">
            <result>/jsp/welcome2.jsp</result>          
        </action>