我在我的应用程序中使用包含jspInit()方法初始化一些资源的jsp文件。 我试图在jsp文件的init方法中获取协议(http/https/ftp),以使用http/https连接启用应用程序url。如何在jspInit()方法中获取模式(http/https)?
代码:
<%!public void jspInit() {
String realPath = getServletContext().getRealPath("/");
ServletContext servletContext = getServletConfig().getServletContext();
// how to get ServletRequest like servletcontext, So that we can get protocol from servletRequest.
}
%>
我见过的ServletRequest接口有 'getScheme()' 方法,但我不知道如何获得的ServletRequest在jspInit()。
任何机构能告诉我如何在jsp中获取模式吗?
*您无法*在jspInit方法中获取_request scheme_,因为没有请求从中获取requestUri。 – gtosto
谢谢@gtosto,请问我知道有没有在jspInit()中获取模式的方法。 –
我很抱歉,但实际上没有办法在该方法中获取请求方案。我试图写一个更具说服力的答案。我希望它有帮助。 – gtosto