Spring MVC:HTTP 状态 404 - /SimpleMVC/WEB_INF/HelloPage。jsp

Spring MVC : HTTP Status 404 - /SimpleMVC/WEB_INF/HelloPage.jsp

我正在尝试开发一个简单的 Spring MVC 网络应用程序。 我收到 HTTP 状态 404 - /SimpleMVC/WEB_INF/HelloPage.jsp 请求的资源不可用。 我是 Spring MVC 的新手。

这是我的web.xml

 <?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 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
      <display-name>SimpleMVC</display-name>
      <servlet>
      <servlet-name>front-controller</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      </servlet>

      <servlet-mapping>
      <servlet-name>front-controller</servlet-name>
      <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>

这是我的前置控制器。

    <bean name="/welcome.html" class="controller.HelloController"></bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix"> <value>/WEB_INF/</value>
    </property>
    <property name="suffix"> <value>.jsp</value></property>
    </bean>

这是我的控制器:

 package controller;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.AbstractController;



    public class HelloController extends AbstractController {

        @Override
        protected ModelAndView handleRequestInternal(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
            ModelAndView giveBackMessage = new ModelAndView("HelloPage");
            giveBackMessage.addObject("welcomeMessage","This is the response got from Controller");
            return giveBackMessage;
        }




    }
This is my Response JSP:


 <html>
    <body>
    <h1>$(welcomeMessage)</h1></body>
    </html>



I dont know where i am missing. Please help me where i am going wrong

您在 viewResolver 中提到了错误的前缀。

<property name="prefix"> <value>/WEB_INF/</value>

正确的应该是

<property name="prefix"> <value>/WEB-INF/</value>

还有 <h1>$(welcomeMessage)</h1></body>

应该是

<h1>${welcomeMessage}</h1></body>