Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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
SpringWebMVC无法访问intellij中的jsp文件_Jsp_Spring Mvc_Tomcat_Servlets_Intellij Idea - Fatal编程技术网

SpringWebMVC无法访问intellij中的jsp文件

SpringWebMVC无法访问intellij中的jsp文件,jsp,spring-mvc,tomcat,servlets,intellij-idea,Jsp,Spring Mvc,Tomcat,Servlets,Intellij Idea,我已经在INTELLIJ ide中配置了一个SpringWebMVC项目。我遵循的教程中说localhost:8080/dispatcher/hello将显示hello.jsp。但是在浏览器中,我发现“未找到文件”。我已经检查了很多类似的问题,但没有一个对我有效。启动后,服务器显示index.jsp,服务器是tomat。 Hello控制器 @Controller @RequestMapping("/hello") public class HelloController { @Req

我已经在INTELLIJ ide中配置了一个SpringWebMVC项目。我遵循的教程中说localhost:8080/dispatcher/hello将显示hello.jsp。但是在浏览器中,我发现“未找到文件”。我已经检查了很多类似的问题,但没有一个对我有效。启动后,服务器显示index.jsp,服务器是tomat。

Hello控制器

@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping(method = RequestMethod.GET)
    public String printHello(ModelMap model) {
        model.addAttribute("message", "Hello Spring MVC Framework!");
        return "hello";
    }

}
应用程序上下文

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <context:component-scan base-package="com.tutorialspoint" />
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

调度servlet

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <mvc:default-servlet-handler/>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>
</web-app>

上下文配置位置
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
*.jsp
人工制品

<component name="ArtifactManager">
  <artifact type="exploded-war" name="SpringWeb:war exploded">
    <output-path>$PROJECT_DIR$/out/artifacts/SpringWeb_war_exploded</output-path>
    <root id="root">
      <element id="javaee-facet-resources" facet="SpringWeb/web/Web" />
      <element id="directory" name="WEB-INF">
        <element id="directory" name="classes">
          <element id="module-output" name="SpringWeb" />
        </element>
        <element id="directory" name="lib">
          <element id="library" level="application" name="Spring MVC-4.3.7.RELEASE" />
          <element id="library" level="project" name="Spring-4.3.7.RELEASE" />
        </element>
      </element>
    </root>
  </artifact>
</component>

$PROJECT\u DIR$/out/artifacts/SpringWeb\u war\u
我想

你怎么换行

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

调度员
/
如果要使用“*.jsp”之类的命令, 您应该使用
或。。。您正在设置容器。
(因为,如果您在Webapp中键入
,WAS容器的设置将被忽略)

我看不出
dispatcher/hello
将如何与您的配置映射到
WEB-INF/jsp/hello.jsp
。您能描述一下哪些配置选项可以进行这种映射吗?无需分析其他配置(并假设它们可以工作)如果您的运行配置将工件映射到
/
我是新手,那么控制器应该映射到
/hello
而不是
/dispatcher/hello/
。您能推荐url应该是什么,或者通过什么更改我可以访问这些jsp文件吗。