0

Web サイトに画像を追加するフォームを配置し、追加したページでページを更新したいと考えています。すべての写真を含むオブジェクト (「カタログ」) を使用し、それをセッション属性に入れます。次に、jsp ファイルはこの属性を取得し、この属性のすべてのデータを表示します。オブジェクト「カタログ」を新しい画像で更新するには、「サーブレット追加ページ」にこの属性が必要です。初めて写真を追加するとき、それは魅力のように機能します。しかし、「ホーム」ページをリロードした後、属性セッションは自動的に削除されます。そのため、別の画像を追加するために「サーブレット ページの追加」を思い出せません。

この属性がどこで削除されたのかわかりません!

Home.java :

@WebServlet("/Home")
public class Home extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Catalogue catalogue = LectureCatalogue.read();
    request.getSession(true).setAttribute("catalogue", catalogue);
    this.getServletContext().getRequestDispatcher("/Catalogue.jsp").forward(request,response);
}

Catalog.jsp :

<?xml version="1.0" encoding="utf-8" ?>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"  session="true" %>
<jsp:useBean id="catalogue" scope="session" class="catalogue.Catalogue"></jsp:useBean>
...
<form class="form-inline" action="Ajout" method="post" enctype="multipart/form-data">
...
</form>

Ajout.java :

@WebServlet("/Ajout")
public class Ajout extends HttpServlet {
    ...
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        System.out.println(session.getAttribute("catalogue")); //not null
        ... //I update the attribute session named "catalogue" here
        session.setAttribute("catalogue", catalogue);
        this.getServletContext().getRequestDispatcher("/Home").forward(request,response);

SessionAttributeListener はこれを返します... :

[SessionAttr] Sun Apr 17 22:03:45 EEST 2016 Attribute added
[SessionAttr] Sun Apr 17 22:04:53 EEST 2016 Attribute replaced
[SessionAttr] Sun Apr 17 22:04:54 EEST 2016 Attribute removed

ご協力いただきありがとうございます。

4

0 に答える 0