ResponseBody的EL返回不适用于JSP

时间:2019-04-10 04:14:00

标签: javascript ajax spring-mvc jsp el

我的页面在$(document).ready()函数上执行分页脚本     然后使用ajax调用控制器     像这样的ajax成功功能

function(data){
    $("#target").html(data);
}

并且我的控制器确实返回String     ..... $ {list [i(循环索引)]。member}(!这是我的问题)...

所以我的页面只能在div ,, classes上工作,但是只有$ {}不起作用,并且它     在浏览器上以自己的格式打印($ {list [i] .member})

我在映射方法上使用注释

我使用spring 4 eclipse,chrome浏览器,tomcat 8.5,oracle 10数据库

```
@ResponseBody
    @RequestMapping("/news_list.do")
    public String newslist(@RequestParam("page") String page) throws UnsupportedEncodingException {

        String res = "";
        int cnt = Integer.parseInt(page);
        String f1 = "${newslist[";
        String f2 = "].";
        String f3 = "}";
        for(int i =cnt ;i<cnt+10 ;i++ ) {
            System.out.println("asdasd"+i);
            res +="<div class='row mb-2'>"
                    + "<div class='col-md-12'>"
                    + "<div class='card bg-warning'>"
                    + "<div class='card-body'>"
                    + "<div class='row'><div class='col-md-4'>"
                    + "<img src='http://www.3forty.media/cannix/wp-content/uploads/2018/03/clem-onojeghuo-127166-unsplash-1-500x333.jpg'>"
                    + "</div><div class='col-md-8'>"
                    + "<div class='news_title'>"
                    + "<h5><a href='' onclick='newsnumfind();' value="
                    + f1 + i + f2 + "news_number" + f3
                    + "> "
                    + "${newslist["+i+"].title}"
                    + " </a></h5></div>"
                    + "<div class='news-cats'><ul class='list-unstyled list-inline mb-1'>"
                    + "<li class='list-inline-item'><iclass='fa fa-folder-o text-danger'></i>"
                    + "<a href='news_body.do'><small> "
                    + f1 + i + f2 + "category" + f3
                    + " </small></a></li>"
                    + "<li class='list-inline-item'><i class='fa fa-folder-o text-danger'></i>"
                    + "<a href='news_body.do'><small>"
                    + f1 + i + f2 + "author" + f3
                    + "</small></a></li>"
                    + "<li class='list-inline-item'><iclass='fa fa-folder-o text-danger'></i>"
                    + "<a href='news_body.do'><small>"
                    + f1 + i + f2 + "postTime" + f3
                    + "</small></a></li></ul></div>"
                    + "<div class='news-content'><p>"
                    + f1 + i + f2 + "contents" + f3
                    + "</p></div>"
                    + "<div class='news-buttons'><a href=''>"
                    + "<button type='button' class='btn btn-outline-danger btn-sm' value="
                    + f1 + i + f2 + "news_number" + f3
                    + " onclick = 'newsnumfind();'>본문 보기</button>"
                    + "</a></div></div></div></div></div></div></div>";
        }


        return res;
    }
```

i expect list by html tags and E'L value
but only html does work and E'L print it's own literals

0 个答案:

没有答案