简体   繁体   English

无法获取Java Servlet的请求中设置的JSP中的属性?

[英]Not getting the attribute in jsp which is set in request in java servlet?

I am using gwt and the gwt is including in my jsp like below 我正在使用gwt并且gwt包含在我的jsp中,如下所示

Once i clicked the menu item it is taking me to myJsp.jsp which includes gwt module and i am displaying form with upload button. 单击菜单项后,它将带我进入myJsp.jsp,其中包括gwt模块,并且我正在显示带有上载按钮的表单。 Once i click the upload, it is uloading a file (and get the blobKey) and returns back to the same jsp(myJsp.jsp) but here before dispatching to this jsp(second time) i am setting one attribute in the request. 单击上传后,它正在加载文件(并获取blobKey)并返回到相同的jsp(myJsp.jsp),但在此之前,在分派给该jsp(第二次)之前,我在请求中设置了一个属性。

I am trying to get that attribute in the jsp by using ${ImportId} but i am getting empty value. 我试图通过使用$ {ImportId}在jsp中获取该属性,但是我得到的是空值。

The below is my jsp. 下面是我的jsp。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<html>
  <head>
    <script type="text/javascript" language="javascript" src="/ActivityLog/ActivityLog.nocache.js">
    </script>
  </head>
  <body>
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' class="iframe"></iframe>
    <div class="wrapper"> 
      <input type="hidden" name="memcacheHeaderId" value="${importId}" />
      <div id="activityLogModule">
      </div>
    </div>
    </div>
</body>
</html>
  1. When ever executing gwt module ${importId} is null. 当执行gwt模块时,$ {importId}为null。
  2. Second time before dispatching to this jsp, i am setting request.setAttribute("importId", importId); 第二次调度到该jsp之前,我正在设置request.setAttribute("importId", importId); but in the jsp i am not getting this value 但是在jsp中我没有得到这个值

What might be the reason, Is there scope problem? 可能是什么原因,是否存在范围问题?

唯一的原因是您正在请求中设置值,当请求完成时,服务器将放弃您的请求。

when you are setting 设置时

request.setAttribute("importId", importId); request.setAttribute(“ importId”,importId);

Than you must be redirecting to the JSP, which creates a new Request for the JSP to the Server. 比您必须重定向到JSP,后者将向服务器创建一个新的JSP请求。 Meaning server creates a new request object and does not remembers the old object with your attribute set into it. 含义服务器将创建一个新的请求对象,并且不会记住设置了属性的旧对象。

I am not much aware of gwt but in JSP-Servlet, there are 2 mechanisms 1)Redirect and 2)Forward. 我对gwt不太了解,但是在JSP-Servlet中,有2种机制1)Redirect和2)Forward。 we use Forward mechanism to go to the JSP with the Same request object, so the attribute which is set into the Object is available on the JSP as well, because it is a copy of the request object passed in the Request. 我们使用Forward机制将带有Same请求对象的JSP转到JSP,因此设置到Object中的属性在JSP上也可用,因为它是在Request中传递的请求对象的副本。

So please check what you can do in GWT. 因此,请检查您可以在GWT中执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM