Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.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 将基本请求重定向到特定jsp_Java_Spring_Spring Mvc_Redirect - Fatal编程技术网

Java 将基本请求重定向到特定jsp

Java 将基本请求重定向到特定jsp,java,spring,spring-mvc,redirect,Java,Spring,Spring Mvc,Redirect,我刚接触Spring,我知道这是一个新手问题,但我并没有在web上找到解决方案我正在开发应用程序,我必须将所有请求从base重定向到index(例如mysite.com/必须重定向到mysite.com/index)。 我已经根据这个完成了: 我创建了BaseController类并声明了/的映射 代码如下: /** * Index. * * @return the string * @throws IOException */ @RequestMapping(method = Re

我刚接触Spring,我知道这是一个新手问题,但我并没有在web上找到解决方案
我正在开发应用程序,我必须将所有请求从base重定向到index(例如mysite.com/必须重定向到mysite.com/index)。

我已经根据这个完成了:
我创建了BaseController类并声明了/的映射

代码如下:

/**
 * Index.
 *
 * @return the string
 * @throws IOException 
 */
@RequestMapping(method = RequestMethod.POST, value = "/")
public void index(HttpServletResponse response) throws IOException {
    response.sendRedirect("/index");
}
它可以很好地处理以下格式的请求:
mysite.com/appname/
,并重定向到
mysite.com/index
,但在这种情况下,我得到404,因为它与
mysite.com/appname/index
一起工作

我知道这与安装有关,但我不知道是什么。

这是我的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">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

上下文配置位置
/WEB-INF/spring/root-context.xml
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/appServlet/servlet-context.xml
1.
appServlet
/
注意,
mysite.com/appname/index
上的所有功能都正常,但我需要以下格式:
mysite.com/index


如果您需要其他信息,我会发布。

有人能帮我吗?谢谢。

也许我误解了你的问题,但你说

注意,
mysite.com/appname/index
上的所有功能都正常,但我需要 以下格式:
mysite.com/index

/appname
部件不是Spring配置。它是一个Servlet容器配置,称为上下文路径

根据Servlet容器的不同,您可以更改每个web应用程序的上下文路径。在这种情况下,您可以将其设置为
/


对于Tomcat,您将找到如何更改它。

/appname
您的上下文路径吗?我还没有定义上下文路径。我来查一下。