Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.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

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
Java 为什么org.springframework.web.servlet.handler.BeannameulHandlerMapping不起作用?_Java_Spring Mvc_Servlets - Fatal编程技术网

Java 为什么org.springframework.web.servlet.handler.BeannameulHandlerMapping不起作用?

Java 为什么org.springframework.web.servlet.handler.BeannameulHandlerMapping不起作用?,java,spring-mvc,servlets,Java,Spring Mvc,Servlets,我是春季Mvc的初学者。 我使用了BeannameulHandlerMapping。 当我从url调用页面时,完成所有映射后,发生404错误。 我将如何解决这个问题 spring-dispatcher-servlet.xml文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/d

我是春季Mvc的初学者。 我使用了BeannameulHandlerMapping。 当我从url调用页面时,完成所有映射后,发生404错误。 我将如何解决这个问题

spring-dispatcher-servlet.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" 
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
<!-- Default hander mapping -->
<!-- handler -->

<bean  id="HandlerMapping" class=" org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<!-- controller -->

<bean name="/hello.html" class="main.Hellocontroller"></bean>







<!-- View Reserver -->
<bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="prefix" value="/WEB-INF"/>
         <property name="suffix" value=".jsp"/>
     </bean>

</beans>
Hellopage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>Hiiii</h1>
<h1>


${messege} 

</h1>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Hello Page</title>
    </head>
    <body>
        <h1>Hello Page </h1>
        ${requestScope.message}
    </body>
</html>

在此处插入标题
Hiiii
${messege}

我试图通过修改您的代码来澄清问题

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" 
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
<context:component-scan base-package="com.example.springmvc" /> <!-- base package where spring will scan for Component like Controller,Service,Repository etc-->
<mvc:annotation-driven/>

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

</beans>
index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Index</title>
    </head>
    <body>
        <h1>Home Page </h1>
        <a href="${pageContext.servletContext.contextPath}/welcome">Click Here</a>
    </body>
</html>

指数
主页
Hellopage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>Hiiii</h1>
<h1>


${messege} 

</h1>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Hello Page</title>
    </head>
    <body>
        <h1>Hello Page </h1>
        ${requestScope.message}
    </body>
</html>

你好,佩奇
你好,佩奇
${requestScope.message}

请确保您的jsp页面位于WEB-INF目录中。

我试图通过修改您的代码来澄清问题

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" 
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
<context:component-scan base-package="com.example.springmvc" /> <!-- base package where spring will scan for Component like Controller,Service,Repository etc-->
<mvc:annotation-driven/>

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

</beans>
index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Index</title>
    </head>
    <body>
        <h1>Home Page </h1>
        <a href="${pageContext.servletContext.contextPath}/welcome">Click Here</a>
    </body>
</html>

指数
主页
Hellopage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>Hiiii</h1>
<h1>


${messege} 

</h1>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Hello Page</title>
    </head>
    <body>
        <h1>Hello Page </h1>
        ${requestScope.message}
    </body>
</html>

你好,佩奇
你好,佩奇
${requestScope.message}

确保您的jsp页面位于WEB-INF目录中。

启动应用程序时日志文件中有任何异常吗?@jens no exceptionurl模式用于dispatcher servlet的是
*。do
而用于controller的是
hello.html
。将dispatcher servlet的url模式更新为
*.html
@Md Zahid Raza如果执行此更改,则会显示1个异常。“HTTP状态500-Servlet spring dispatcher的Servlet.init()引发异常”javax.Servlet.ServletException:Servlet spring dispatcher的Servlet.init()引发异常。org.springframework.beans.factory.BeanDefinitionStoreException:IOException解析来自ServletContext资源的XML文档[/WEB-INF/spring dispatcher Servlet.XML];嵌套异常为java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/spring dispatcher servlet.xml]这很奇怪。异常与更改dispatcher servlet的url模式无关。启动应用程序时日志文件中是否存在异常?@jens no exceptionurl模式适用于dispatcher servlet的是
*。do
,controller的是
hello.html
。将dispatcher servlet的url模式更新为
*.html
@Md Zahid Raza如果执行此更改,则会显示1个异常。“HTTP状态500-Servlet spring dispatcher的Servlet.init()引发异常”javax.Servlet.ServletException:Servlet spring dispatcher的Servlet.init()引发异常。org.springframework.beans.factory.BeanDefinitionStoreException:IOException解析来自ServletContext资源的XML文档[/WEB-INF/spring dispatcher Servlet.XML];嵌套异常为java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/spring dispatcher servlet.xml]这很奇怪。异常与更改dispatcher servlet的url模式无关。您是否会从繁忙的日程中抽出一些时间。我将在TeamViewer中向您展示所有内容。如果有可能。相同的错误显示。HTTP状态404-我已为您创建了一个演示项目。您可以从下载并学习完整的代码。我还编辑了spring配置文件。您可以修改并查看项目是否正常工作。如果没有,请下载演示项目并查看完整的详细信息。您是否会从繁忙的日程中抽出一些时间。我将在TeamViewer中向您展示所有内容。如果有机会。相同的错误显示。HTTP状态404-我已为您创建了一个演示项目。您可以从下载并学习完整的代码。我还编辑了spring配置文件。您可以修改并查看项目是否正常工作。如果没有,请下载演示项目并查看完整的详细信息