0
我想传递一个对象到的servelt用了request.setAttribute方法,像这样:如何从一个jsp页面传递一个对象到一个servlet没有会话属性
的jsp:
<%request.setAttribute(ResponsibilitiesCollectionRdg.RESPONSIBILITIES_COLLECTION, new ResponsibilitiesCollectionRdg());%>
Java代码:
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梅索德后包含空。任何想法如何解决我的问题?
您是否正在尝试在处理一个请求期间设置该值,并在处理下一个请求期间检索该值? – 2013-02-20 19:09:22
当用户选中一个复选框时,复选框的ID将存储在request.setAttribute中,然后它将调用发送到ajax函数以使用java类。 – Riri 2013-02-20 19:12:00