【问题标题】:RequestDispatcher dumping html page inside input fieldRequestDispatcher 在输入字段中转储 html 页面
【发布时间】:2017-07-23 23:06:28
【问题描述】:

如何避免调度程序将整个 HTML 页面推送到输入字段中。

下面是代码...它附加到我的会话变量并将页面的其余部分转储到输入字段中。

小服务程序:

    Cookie sCookie = new Cookie("id", id);
    response.addCookie(sCookie);
    HttpSession session= request.getSession(true);
    session.setAttribute("id",id);

    RequestDispatcher rd = getServletContext().getRequestDispatcher("/student.jsp");
    rd.include(request, response);

HTML 端(Student.jsp 被转储到下面的输入字段中):

 <input name="id" id="id" value=<%=id%>>

【问题讨论】:

    标签: javascript java html jsp servlets


    【解决方案1】:

    使用

    request.getRequestDispatcher("path to page").forword(...);
    

    而不是rd.include(...);

    尝试编码

    session.setAttribute("id", id.getValue());
    

    【讨论】:

    • 已经试过了,rd.forward(request, response);不工作。
    • Cookie 类也有方法。在这种情况下,您将对象作为值传递,而不是将 cookie 数据作为值传递
    【解决方案2】:

    没关系。结束了: result = result.substring(0, result.indexOf('\n'));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-25
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多