Java spring mvc资源处理程序路径

时间:2017-08-16 15:17:40

标签: java spring maven spring-mvc netbeans

我是Java EE Spring Framework的新手。 我正在Netbeans中运行一个spring mvc spring maven项目,我在" Web Pages"项目文件中的目录:

-Web页面
--Web-INF
---观点
----的welcome.jsp
-resources
--DPI.PNG

这是配置类:

公共类HelloWorldConfiguration {

@Bean(name = "HelloWorld")
public ViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");

    return viewResolver;
}

public void addResourceHandlers(ResourceHandlerRegistry registry) {

    // Css resource.
    registry.addResourceHandler("/resources/**") //
            .addResourceLocations("/resources/");

}

}

在welcome.jsp中我使用以下html访问图像:

<img src='/resources/DPI.PNG'>

当我访问该页面时,它为图像找不到404,

问题是什么?

1 个答案:

答案 0 :(得分:0)

尝试使用包含应用程序上下文路径的jstl标记。

function Finding(id, trigger) {
    var self = this;
    self.id = ko.observable(id);
    self.trigger = ko.observable(trigger);
}

function FindingViewModel() {
    let self = this;

    self.findings = ko.observableArray();

    self.addFinding = function () {
        self.findings.push(new Finding(self.findings().length + 1, ""));
    };
    self.removeFinding = function (finding) {
        self.findings.remove(finding);
        ko.utils.arrayForEach(self.findings(), function (value, i) {
            self.findings.replace(value, new Finding(i + 1, value.trigger()));
        });
    };
    self.update = function (data) {
        var findings = data.findings;
        for (var index = 0; index < findings.length; ++index) {
            var finding = findings[index];
            self.findings.push(new Finding(self.findings().length + 1, finding.trigger));
        }

    };
}

ko.components.register('finding', {
    template: `<table>
            <tbody data-bind="foreach: findings">
            <tr>
            <td><span data-bind="text: id"/></td>
            <td><input data-bind="value: trigger"/></td>
            <td><a href="#" data-bind="click: $parent.removeFinding">Remove</a></td>
            </tr></tbody></table>
            <button data-bind="click: addFinding">Add a Finding</button>`,

    viewModel: FindingViewModel

});

$(function () {
    ko.applyBindings();
    $.getJSON("/_get_findings", function (data) {
        //findingModel.update(data);
    })
});