我正在尝试使用 request.setAttribute 方法将对象传递给servelt,如下所示:
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
}
变量“respos”在 getAttribute 方法之后包含 null。任何想法如何解决我的问题?