gpt4 book ai didi

jsp - Spring Web MVC在intellij中无法访问jsp文件

转载 作者:行者123 更新时间:2023-11-28 23:21:15 25 4
gpt4 key购买 nike

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

你好 Controller

@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>

网络.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>

人工制品

<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>

最佳答案

我觉得..

你会如何换行

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

如果你想像“*.jsp”那样使用,你应该使用 <jsp-config>或者...您的 WAS 容器设置。(因为,如果您在 Webapp 中键入 <servlet-mapping>,WAS 容器的设置将被忽略)

关于jsp - Spring Web MVC在intellij中无法访问jsp文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43399646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com