Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.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 如何通过index.html spring更改index.jsp_Java_Spring_Spring Mvc - Fatal编程技术网

Java 如何通过index.html spring更改index.jsp

Java 如何通过index.html spring更改index.jsp,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在尝试将spring与angularjs结合使用,所以我需要将默认页面设置为html文件。我看到它可以使用mvc:resources将url映射到目录位置,但无法使其工作,服务器永远找不到该页面。如果我使用viewResolver,效果会很好,但这不是我的目标 这是我的dispatcher-servlet.xml: 你能告诉我我做错了什么吗?提前谢谢 我将html文件夹移动到Web Pages目录 然后我把这一行改成了这一行,并按预期工作。谢谢大家的帮助。如果服务器找不到该页面,那么肯定是资

我正在尝试将spring与angularjs结合使用,所以我需要将默认页面设置为html文件。我看到它可以使用mvc:resources将url映射到目录位置,但无法使其工作,服务器永远找不到该页面。如果我使用viewResolver,效果会很好,但这不是我的目标

这是我的dispatcher-servlet.xml:


你能告诉我我做错了什么吗?提前谢谢

我将html文件夹移动到Web Pages目录


然后我把这一行改成了这一行,并按预期工作。谢谢大家的帮助。

如果服务器找不到该页面,那么肯定是资源路径问题。查看浏览器中的URL路径。使用它并尝试调整index方法的返回值。@vinay url路径为http://localhost:8084/HelloSpring/,所以它应该根据controller html/index.html页面进行渲染,对吗?请尝试将您的资源移出WEB-INF目录。@LaszloLugosi我收到了相同的错误为什么您需要index.html而不是index.jsp?您可以使用.jsp,它也可以工作。AngularJS是客户端的,它不重要,也不知道您的原始模板是jsp还是html文件。很好,您已经让它工作了。是否实际使用了DefaultController?是的@vinay,它使用默认控制器加载html/index.html作为主页。我并不认为它使用的是DefaultController。尝试调试/删除DefaultController。是的@vinay,我尝试调试代码,它正在使用DefaultController,为什么您认为它没有?因为您使用的是mvc:resources标记。AFAIK标签负责映射请求。我可能错了。你可能只是想检查一下。
<?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:mvc="http://www.springframework.org/schema/mvc"
       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
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.outbottle" />
    <mvc:annotation-driven />
    <mvc:resources mapping="/**" location="/html/" />

    <!--Old code-->
    <!--bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/html/"
              p:suffix=".jsp" /-->

</beans>
@Controller
public class DefaultController {

    @RequestMapping(value="/", method= RequestMethod.GET)
    public String index(ModelMap map) {
        map.addAttribute("hello", "Hello Spring from Netbeans!!");
        return "html/index.html";
    }

    /*Old code*/
    /*@RequestMapping(value="/", method= RequestMethod.GET)
    public String index(ModelMap map) {
        map.addAttribute("hello", "Hello Spring from Netbeans!!");
        return "index";
    }*/

}