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 HTTP状态404。请求的源不可用_Java_Spring_Jsp - Fatal编程技术网

Java HTTP状态404。请求的源不可用

Java HTTP状态404。请求的源不可用,java,spring,jsp,Java,Spring,Jsp,我对java和spring还是新手,目前我正在尝试将/buku/映射到my home.jsp,但它似乎不起作用 HomeController.java home.jsp web.xml book-servlet.xml 我运行我的tomcat服务器并试图访问localhost:8080/buku/但它不起作用,请继续向我提供HTTP状态404-/buku/error尝试添加book-servlet.xml以扫描控制器 <?xml version="1.0" encoding="UTF-8"

我对java和spring还是新手,目前我正在尝试将/buku/映射到my home.jsp,但它似乎不起作用

HomeController.java

home.jsp

web.xml

book-servlet.xml

我运行我的tomcat服务器并试图访问localhost:8080/buku/但它不起作用,请继续向我提供HTTP状态404-/buku/error

尝试添加book-servlet.xml以扫描控制器

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   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
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

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

</beans>
别忘了添加mvc名称空间


更新:我还注意到您没有指定请求方法。使用@RequestMappingvalue=/,method=RequestMethod重新调用@RequestMapping/。获取并尝试删除方法-home上方的RequestMapping注释?

是否要将/book/home映射到home.jsp? 我认为您打算将/book/home路径映射到HomeController的home方法。。。然后试试下面的方法

@Controller
public class HomeController {

    private static Logger logger =Logger.getLogger(HomeController.class);

    @RequestMapping("book/home")
    public String home(ModelMap model){

        model.addAttribute("message", "Hello Spring MVC Framework!");
        return "home";
    }
}

现在,当您点击URL:localhost:8080/buku/book/home时,应该会显示home.jsp

启动web服务器时是否显示任何错误?因为你甚至不能访问project base根路径。也许你应该下载其他人的项目。看看他们之间的不同。这是最好的方法。很抱歉,我的意思是将“/buku/”映射到主页。jsp@jourpool-您是否尝试过URL:localhost:8080/buku谢谢您的回复,但仍然无法解决问题hmmm。。真奇怪。您有安全配置吗?尝试暂时删除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"
    version="2.5">

    <display-name>buku</display-name>
    <description>Database of Buku</description>
    <servlet>
        <servlet-name>book</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>book</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/book-servlet.xml</param-value>
    </context-param>

    <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <session-config>
        <session-timeout>120</session-timeout>
    </session-config>

</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   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.web.buku" />

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

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   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
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

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

</beans>
@Controller
public class HomeController {

    private static Logger logger =Logger.getLogger(HomeController.class);

    @RequestMapping("book/home")
    public String home(ModelMap model){

        model.addAttribute("message", "Hello Spring MVC Framework!");
        return "home";
    }
}