Java 如何在没有会话属性的情况下将对象从jsp页面传递到servlet
我尝试使用request.setAttribute方法将对象传递给servelt,如下所示: jsp:Java 如何在没有会话属性的情况下将对象从jsp页面传递到servlet,java,ajax,jsp,Java,Ajax,Jsp,我尝试使用request.setAttribute方法将对象传递给servelt,如下所示: jsp: 变量“respos”在getAttribute方法之后包含null。有什么办法解决我的问题吗?一旦处理了jsp,它就会呈现为html并提交到HttpResponseOutputStream。jsp不再存在于servlet的上下文中,因此您不能以您可能认为的方式传递任何内容 您可以做的是为下一个Http请求提供参数,从锚点或表单提交中,输入用作请求参数的元素。是否尝试在处理一个请求期间设置值,并
变量“respos”在getAttribute方法之后包含null。有什么办法解决我的问题吗?一旦处理了
jsp
,它就会呈现为html并提交到HttpResponse
OutputStream
。jsp
不再存在于servlet的上下文中,因此您不能以您可能认为的方式传递任何内容
您可以做的是为下一个Http请求提供参数,从锚点
或表单提交
中,输入用作请求参数的元素。是否尝试在处理一个请求期间设置值,并在处理下一个请求期间检索值?当用户选中复选框时,复选框的id存储在request.setAttribute中,然后它向ajax函数发送一个调用以使用java类。
<%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
}