转发jsp - 丢失会话?与春天mvc

时间:2014-07-10 13:18:35

标签: java spring hibernate jsp

我正在开发一个带有hibernate和spring mvc的web应用程序。主要的问题是,我有一个jsp页面,其上有提交按钮。每当用户点击其中一个时,字符串就会保存在列表中。这很好,但问题是,当其他人登录我的应用程序(一次2个或更多用户)时,我们就制作了“我们的”列表。所有用户都将字符串添加到同一个列表中。

我用过,之前jsf +管理bean,在那种情况下还可以。

谁能告诉我该怎么办?我没有想法。我所看到的,在第一个显示页面上是带参数的url(usersName和usersPassword),然后在表单重定向之后只有一个页面名称“Tickets.htm”。

这是我的代码:

Ticket.jsp - 用户可以将所有内容添加到一个列表的页面。

    <div id="Tickets">
        <c:forEach items="#{TicketList}" var="Ticket" >
            <spring:form method="POST" action="Tickets.htm">
                <input type="Submit" value="${Ticket.name}" name="Button" />
                <input type="hidden" value="${Ticket.name}" name="Hidden" />
                <input type="hidden" value="${WebUser.name}" name="userName" alt="Nothing"/>
                <input type="hidden" value="${WebUser.password}" name="userPassword" alt="Nothing" />
                <br> 
            </spring:form>
        </c:forEach>
    </div>


    <div id="ReservationList" >
        Lista: <br>
        <c:forEach items="#{ReservedTicketList}" var="Ticket" >

            <input type="button" value="${Ticket}" />
            <br> 
        </c:forEach>
    </div>

    <div id="Menu">
        <input type="Submit" value="Zarezerwuj" />
    </div>

TicketController - 控制该页面。方法GET显示TicketList,方法POST显示ReservedTicketList。还有一个吸气剂和制定者。

 @RequestMapping(value = "/Tickets", method = RequestMethod.GET)
public ModelAndView showGet(@RequestParam("userName") String userName,
        @RequestParam("userPassword") String userPassword) {

    ModelAndView model = new ModelAndView("Tickets");

    setWebUser(new WebUser(userName,userPassword));

    String retValue = "";

    Session session = FirebirdHibernateHelper.getSession();
    Transaction transaction = null;

    try {
        transaction = session.beginTransaction();

        String hql = "FROM WebLogin W WHERE W.emailaddress =:userName AND W.userpassword =:userPass";
        Query query = session.createQuery(hql);
        query.setParameter("userName", webUser.getName());
        query.setParameter("userPass", webUser.getPassword());

        List results = query.list();

        WebLogin user = (WebLogin) results.get(0);

        if (!user.getEmailaddress().trim().equals(userName)) {
            model.addObject("message", "Nie ma takiego konta!");
            return model;
        }

        retValue = user.getEmailaddress();

    } catch (Exception ex) {
        retValue = "Nie no tak to nie bedzie!  " + ex.getMessage();
        ex.printStackTrace();
    } finally {
        session.close();
    }

    setTicketsFromDB();
    setReservedTicketList(new ArrayList<String>());

    model.addObject("WebUser", webUser);
    model.addObject("TicketList", TicketList);
    model.addObject("message", retValue);

    return model;
}

List<WetBarAssortModel> TicketList;
List<String> ReservedTicketList;

public void setTicketsFromDB() {

    Session session = FirebirdHibernateHelper.getSession();
    try {

        String hql = "FROM WetBarAssortModel W WHERE W.ASSORTTYPE = 'T'";
        Query query = session.createQuery(hql);

        setTicketList((List<WetBarAssortModel>) query.list());

        for (int i = 0; i < getTicketList().size(); i++) {
            //   WetBarAssortModel model = (WetBarAssortModel)result.get(i);
            //     getTicketList().add(model);
            System.out.println("Ticket: " + getTicketList().get(i).getName());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        session.close();
    }
}

@RequestMapping(value = "/Tickets", method = RequestMethod.POST)
public ModelAndView showPost(@RequestParam("Hidden") String name, 
        @RequestParam("userName") String userName,
        @RequestParam("userPassword") String userPassword) {

    System.out.println("POST NAME: "+userName);
    System.out.println("POST PASS: "+userPassword);


    ModelAndView model = new ModelAndView("Tickets");

    getReservedTicketList().add(name);

    model.addObject("WebUser", webUser);
    model.addObject("ReservedTicketList", getReservedTicketList());
    model.addObject("TicketList", getTicketList());
    return model;

}

我会感激任何帮助。

0 个答案:

没有答案