java 加载 JSP 页面时如何获取 HttpServletRequest 对象?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13461688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:49:43  来源:igfitidea点击:

How do I get a HttpServletRequest object when loading a JSP page?

javajspservlets

提问by mpark

I have a HTML page that allows me to use JSP code. I was able to print some output using some basic Java. But How do I obtain a HttpServletRequest object so I can print some of its properties onto the HTML page?

我有一个允许我使用 JSP 代码的 HTML 页面。我能够使用一些基本的 Java 打印一些输出。但是如何获取 HttpServletRequest 对象以便我可以将其某些属性打印到 HTML 页面上?

采纳答案by Juvanis

Just use the requestvariable (HttpServletRequestinstance). It is one of implicit objectsin JSP. Check properties here: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

只需使用request变量(HttpServletRequest实例)。它是 JSP 中的隐式对象之一。在此处检查属性:http: //docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

<%
    request.getHeader();
%>