jsp include,转发请求参数 [英] Jsp include, forwarding request parameter

查看:91
本文介绍了jsp include,转发请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 jsp 文件中,我通过 request.getAttribute() 从请求中提取数据.

In my jsp file I am pulling data from the request via request.getAttribute().

在这个jsp里面我需要包含另一个jsp.这个包含的jsp是否可以访问请求,或者我是否需要以某种方式转发数据?

Inside this jsp I need to include another jsp. Will this inluded jsp have access to the request, or do I need to somehow forward on the data?

推荐答案

它将可用:

  • 如果您正在执行静态包含 (<%@ include file=".." %>),则包含文件的正文将放入 生成的servlet的doGet(..)方法(每个JSP都转换成一个servlet),所以从逻辑上讲,原始request对象在那里是可以访问的.

  • if you are doing a static include (<%@ include file=".." %>) then the body of the included file is placed into the doGet(..) method of the generated servlet (each JSP is converted to a servlet), so logically, the original request object is accessible there.

如果您正在执行动态包含 (<jsp:include>),则使用 RequestDispatcher.include(..)(在幕后).如您所见,它需要一个 ServletRequest 参数,这意味着原始请求被传递到那里.

if you are doing a dynamic include (<jsp:include>), RequestDispatcher.include(..) is used (behind the scene). As you can see, it requires a ServletRequest parameter, which would mean that the original request is passed there.

最后,避免在 JSP 文件中使用 Java 代码.使用 EL 和 JSTL.所以不是 request.getAttribute("x") 这将是 ${x}.

Finally, avoid using Java code in JSP files. Use EL and JSTL. So instead of request.getAttribute("x") this would be ${x}.

这篇关于jsp include,转发请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆