0

次のように、request.setAttribute メソッドを使用してオブジェクトをサーベルトに渡そうとしています。

jsp :

<%request.setAttribute(ResponsibilitiesCollectionRdg.RESPONSIBILITIES_COLLECTION, new ResponsibilitiesCollectionRdg());%>

ジャバコード:

public class ResponsabilityHtmlCommand extends FrontCommand {


@Override
public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 
{

    int id = new Integer(request.getParameter("ID")); //get the id of the module
    boolean toAdd = new Boolean(request.getParameter("toAdd")); // get if we need to add or remove the responsibilities
    ResponsibilitiesCollectionRdg respos = (ResponsibilitiesCollectionRdg) request.getAttribute(ResponsibilitiesCollectionRdg.RESPONSIBILITIES_COLLECTION);
    //add or remove the responsibilities
    if(id != -1)
    {
        if(toAdd)
            respos.addResp(id);
        else
            respos.removeResp(id);
    }

    response.getWriter().write(ResponsabilityFinder.findHtmlForRespDropDown(respos.getListOfResp())); //send the tag
}

getAttribute メソッドの後、変数 "respos" に null が含まれています。私の問題を解決する方法はありますか?

4

1 に答える 1

1

jsp処理されると、htmlにレンダリングされ、にコミットされますHttpResponse OutputStream。サーブレットのjspコンテキストにはもはや存在しないため、思いどおりに何も渡すことができません。

あなたができることは、アンカーから、<a href="/my/wtv/site?attr=myattribute">またはフォーム<form action="/my/wtv/site?attr=myattribute">送信とリクエストパラメータとして使用される入力要素のいずれかで、次に行うHttpリクエストでパラメータを利用できるようにすることです。

于 2013-02-20T19:17:04.233 に答える