Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.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/4/jsp/3.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 为什么在jsp上调用会话会返回错误?_Java_Jsp_Spring Mvc_Session_Jstl - Fatal编程技术网

Java 为什么在jsp上调用会话会返回错误?

Java 为什么在jsp上调用会话会返回错误?,java,jsp,spring-mvc,session,jstl,Java,Jsp,Spring Mvc,Session,Jstl,我在调用jsp文件上的会话时遇到问题。我正在尝试创建一个Spring和Hibernate项目,该项目涉及使用基于Java的配置(无xml配置)的会话。下面是我正在做的事情的快照 这是我的一个控制器: @Controller @RequestMapping(value = "/sp") public class ELibraryController { @RequestMapping(value = "/form") public String index(ModelMap m)

我在调用jsp文件上的会话时遇到问题。我正在尝试创建一个Spring和Hibernate项目,该项目涉及使用基于Java的配置(无xml配置)的会话。下面是我正在做的事情的快照

这是我的一个控制器:

@Controller
@RequestMapping(value = "/sp")
public class ELibraryController {

    @RequestMapping(value = "/form")
    public String index(ModelMap m) {
        m.put("basket", new Basket());
        return "form";
    }

    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/addbasket", method = RequestMethod.POST)
    public String addbasket(@ModelAttribute("basket") Basket b, HttpSession session) {
        List<Basket> lst = (List<Basket>) session.getAttribute("basket");
        if(lst == null) {
            lst = new ArrayList<>();
            lst.add(b);
        }else {
            boolean flag = false;
            for(Basket basket : lst) {
                if(basket.getId()==b.getId()) {
                    basket.setQuantity(basket.getQuantity()+1);
                    flag = true;
                    break;
                }
            }
            if(flag==false)
                lst.add(b);
        }
        session.setAttribute("basket", lst);
        session.setAttribute("total", lst);
        return "basket";
    }

    public int getNoBooksBorrowed(List<Basket> lst) {
        int total = 0;
        for(Basket basket : lst) {
            total += (basket.getQuantity());
        }
        return total;
    }

}
运行时,如果我浏览到,页面将正确显示,但当我单击添加到购物篮按钮时,浏览器指向,但返回以下错误:

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/Elibrary] threw exception [/WEB-INF/views/basket.jsp (line: 13, column: 24) Attribute value  request.getSession().getAttribute("basket")  is quoted with " which must be escaped when used within the value] with root cause
org.apache.jasper.JasperException: /WEB-INF/views/basket.jsp (line: 13, column: 24) Attribute value  request.getSession().getAttribute("basket")  is quoted with " which must be escaped when used within the value
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
...
非常感谢您的帮助

使用单引号

"<%=request.getSession().getAttribute('basket')%>"
“”
或使用

'<%=request.getSession().getAttribute("basket")%>'
“”
使用单引号

"<%=request.getSession().getAttribute('basket')%>"
“”
或使用

'<%=request.getSession().getAttribute("basket")%>'
“”

非常感谢。现在使用第二个就可以了。非常感谢。现在它可以使用第二个。
"<%=request.getSession().getAttribute('basket')%>"
'<%=request.getSession().getAttribute("basket")%>'