Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 创建简单项目时未找到资源获取错误?_Java_Spring_Jsp_Spring Mvc - Fatal编程技术网

Java 创建简单项目时未找到资源获取错误?

Java 创建简单项目时未找到资源获取错误?,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我正在使用MVC在春季制作简单的hello world项目。Hi发现此错误资源未找到。我从此链接获取帮助。 可以复制调用文件。它会打开第一个index.jsp文件,但当我单击该链接时,它会说找不到资源 这是我的错误 我复制所有代码。这是文件代码。 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmln

我正在使用MVC在春季制作简单的hello world项目。Hi发现此错误资源未找到。我从此链接获取帮助。

可以复制调用文件。它会打开第一个index.jsp文件,但当我单击该链接时,它会说找不到资源

这是我的错误

我复制所有代码。这是文件代码。 web.xml

  <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>FirstWebProject</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

    <servlet>
        <servlet-name>crunchify</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
   <servlet-mapping>
    <servlet-name>crunchify</servlet-name>
    <url-pattern>*.jsp</url-pattern>
</servlet-mapping>
    </web-app>
  <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context 

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.crunchify.controller" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

FirstWebProject
index.jsp
嘎吱作响
org.springframework.web.servlet.DispatcherServlet
1.
嘎吱作响
*.jsp
crunchifyservlet.xml

  <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>FirstWebProject</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

    <servlet>
        <servlet-name>crunchify</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
   <servlet-mapping>
    <servlet-name>crunchify</servlet-name>
    <url-pattern>*.jsp</url-pattern>
</servlet-mapping>
    </web-app>
  <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context 

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.crunchify.controller" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

控制器

package com.crunchify.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CrunchifyHelloWorld {

    @RequestMapping("/welcome")
    public ModelAndView helloWorld() {

        String message = "<br><div align='center'>" + "<h1>Hello World, Spring 3.2.1 Example by Crunchify.com<h1> <br>";
        message += "<a href='http://crunchify.com/category/java-web-development-tutorial/'>More Examples</a>";
        return new ModelAndView("welcome", "message", message);
    }
}
package com.crunchify.controller;
导入org.springframework.stereotype.Controller;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.servlet.ModelAndView;
@控制器
公共类CrunchifyHelloWorld{
@请求映射(“/welcome”)
公共模型和视图helloWorld(){
String message=“
”+“Hello World,Crunchify.com提供的Spring 3.2.1示例
”; 消息+=“”; 返回新的ModelAndView(“欢迎”、“消息”、消息); } }
index.jsp

<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
    <br>
    <div align='center'>
    <h2>

            Your 1st Spring MCV Example <br> <br>
            <a href="welcome.jsp">Click here to See Welcome Message...</a>

        </h2>
            <br> by <a href="http://crunchify.com">Crunchify.com</a>
            </div>
</body>
</html>
<html>
<head>
    <title>Spring 3.2.1 MVC Example: Hello World - Crunchify.com</title>
</head>
<body>
    ${message}
</body>
</html>
<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
  <br>
  <div align='center'>
  <h2>

        Your 1st Spring MCV Example <br> <br>
        <a href="welcome.jsp">Click here to See Welcome Message...</a>

  </h2>
  <br> by <a href="http://crunchify.com">Crunchify.com</a>
  </div>
</body>
</html>

Spring 3.2.1 MVC系列:Index-Crunchify.com

您的第一个春季MCV示例


welcome.jsp

<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
    <br>
    <div align='center'>
    <h2>

            Your 1st Spring MCV Example <br> <br>
            <a href="welcome.jsp">Click here to See Welcome Message...</a>

        </h2>
            <br> by <a href="http://crunchify.com">Crunchify.com</a>
            </div>
</body>
</html>
<html>
<head>
    <title>Spring 3.2.1 MVC Example: Hello World - Crunchify.com</title>
</head>
<body>
    ${message}
</body>
</html>
<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
  <br>
  <div align='center'>
  <h2>

        Your 1st Spring MCV Example <br> <br>
        <a href="welcome.jsp">Click here to See Welcome Message...</a>

  </h2>
  <br> by <a href="http://crunchify.com">Crunchify.com</a>
  </div>
</body>
</html>

Spring 3.2.1 MVC示例:Hello World-Crunchify.com
${message}
url正在检查“welcome.html”而不是“welcome.jsp”


嘎吱作响
*.jsp
index.jsp

<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
    <br>
    <div align='center'>
    <h2>

            Your 1st Spring MCV Example <br> <br>
            <a href="welcome.jsp">Click here to See Welcome Message...</a>

        </h2>
            <br> by <a href="http://crunchify.com">Crunchify.com</a>
            </div>
</body>
</html>
<html>
<head>
    <title>Spring 3.2.1 MVC Example: Hello World - Crunchify.com</title>
</head>
<body>
    ${message}
</body>
</html>
<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
  <br>
  <div align='center'>
  <h2>

        Your 1st Spring MCV Example <br> <br>
        <a href="welcome.jsp">Click here to See Welcome Message...</a>

  </h2>
  <br> by <a href="http://crunchify.com">Crunchify.com</a>
  </div>
</body>
</html>

Spring 3.2.1 MVC系列:Index-Crunchify.com

您的第一个春季MCV示例


无论何时使用创建web应用程序,都要在web.xml文件中为欢迎文件列表创建一个条目

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

index.jsp

仔细遵循给定的教程并进行以下更改

web.xml

  <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>FirstWebProject</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

    <servlet>
        <servlet-name>crunchify</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
   <servlet-mapping>
    <servlet-name>crunchify</servlet-name>
    <url-pattern>*.jsp</url-pattern>
</servlet-mapping>
    </web-app>
  <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context 

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan
        base-package="com.crunchify.controller" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>
*.html
读一下这个

index.jsp

<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
    <br>
    <div align='center'>
    <h2>

            Your 1st Spring MCV Example <br> <br>
            <a href="welcome.jsp">Click here to See Welcome Message...</a>

        </h2>
            <br> by <a href="http://crunchify.com">Crunchify.com</a>
            </div>
</body>
</html>
<html>
<head>
    <title>Spring 3.2.1 MVC Example: Hello World - Crunchify.com</title>
</head>
<body>
    ${message}
</body>
</html>
<html>
<head>
<title>Spring 3.2.1 MVC Series: Index - Crunchify.com</title>
</head>
<body>
  <br>
  <div align='center'>
  <h2>

        Your 1st Spring MCV Example <br> <br>
        <a href="welcome.jsp">Click here to See Welcome Message...</a>

  </h2>
  <br> by <a href="http://crunchify.com">Crunchify.com</a>
  </div>
</body>
</html>

当您单击此链接时,将生成新的GET请求并重定向到映射控制器

控制器

@控制器
@请求映射(“/welcome”)
公共类CrunchifyHelloWorld{
@RequestMapping(method=RequestMethod.GET)
公共字符串helloWorld(ModelMap模型,HttpServletRequest){
String message=“
”+“Hello World,Crunchify.com提供的Spring 3.2.1示例
”; 消息+=“”; //将消息添加到模块中 model.addAttribute(“消息”,消息); //要显示的jsp的名称 返回“欢迎”; } }
然后将调用helloWorld()方法,该方法将把消息添加到ModelMap中,并向welcome.jsp文件发送请求


希望这对你有帮助

您是否已将index.jsp中的href值从welcome.html更改为welcome.jsp?并将该index.jsp移动到welcome.jsp存在的jsp文件夹请检查我的更新问题,我仍然收到相同的问题您可以使用MVCI提供一个hello word项目吗?您认为您的库中没有添加任何jar文件。在lib文件夹中添加以下jar,common-logging-x.x.jar jstl-x.x.jar spring-aspects-x.x.jar spring-beans-x.x.jar spring-context-x.x.jar spring-core-x.x.jar spring-expression-x.x.jar spring-webmvc-x.x.jar