有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java I无法在spring mvc中维护会话

我被困了几个小时,但无法检索会话属性。换句话说,在SpringMVC中,从控制器到视图的请求之间不维护会话。我的控制器代码如下:-

@RequestMapping("/search")
    public ModelAndView search(HttpSession session2) {

        session2.setAttribute("name","abhi");
        Session session=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();
        String hql = "SELECT E.firstName FROM User E";
        Query query = session.createQuery(hql);
        List results = query.list();

        //System.out.println(results.get(1).getClass().getFields());
        HashMap model = new HashMap();
        model.put("users", results);
        return new ModelAndView("search", model);
    }

检索会话属性的代码如下所示:-

搜索。jsp

<div id="user"></div>
Welcome <% request.getSession().getAttribute("name"); %>
<%@ taglib prefix="c"
           uri="http://java.sun.com/jsp/jstl/core" %>
<select id="userlist" onchange="a()">
    <option>Select User</option>
<c:forEach items="${users}" var="user">
    <option>${user}</option>
</c:forEach>
    </select>

<script>
    function a()
    {
    document.write('<form method="post" id="chat" action="/abhishekchat/hello" > <input type="text" name="chatbox" id="chatbox"/>' +'Enter the name of the person you want to chat with'
            +'<input type="text" name="name" id="name" />'+
            '<input type="submit"  value="Submit" />' +
            '</form>');
    }

    $



</script>

请帮忙。。thanx提前…)


共 (0) 个答案