获取HTTPS的JSP页面的服务器名称和端口号 [英] get server name and port number of JSP page for HTTPS

查看:363
本文介绍了获取HTTPS的JSP页面的服务器名称和端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为表单操作创建URL,但是表单应在https下提交,当前底层系统在HTTPS的9002端口上运行.我不能在JSP页面中使用以下选项

i need to make the URL for my form action but the form should be submitted under https currently the underlying system running on 9002 port for the HTTPS.I can not use the following option in my JSP page

<form:form action="${request.contextPath}/springSecurity/login"
method="post" commandName="loginForm" target="guestFrame"> 

因为在HTTP中,上下文路径作为HTTP传入,并且系统将引发异常,因为表单应该由HTTPS提交. 我无法对动作URL进行硬编码,因为它的主机名是localhost,即使是HTTPS端口也是可配置的,因此甚至无法进行硬编码.

since when in HTTP the context path is coming as HTTP and the system will throw an exception as form should be submitted by HTTPS. i can not hard code the action URL as currently its under develoment as the host name is localhost, even the HTTPS port is configurable so its even can not be hard-coded.

我是否可以使用JSTL或其他任何方式在JSP中创建URL,以便我可以在HTTPS下提交表单

Is there any way i can create the URL in my JSP using JSTL or any other way so as to i can submit the form under HTTPS

推荐答案

HttpServletRequest.getServerName()将提供服务器名称.但是,没有办法获取https端口.如果要在方法中对其进行修复,则应使用默认的443.

HttpServletRequest.getServerName() will give the server name. But, there is no way to get the https port. You should be using the default 443 if you want to fix it in your approach.

但是好的解决方案是使用Security Transport Guarantee作为登录URL,这样服务器将自动将springSecurity/login页面重定向到https.

But the good solution is to use the Security Transport Guarantee for the login url, such that the server will automatically redirect the springSecurity/login page to https.

将此条目添加到web.xml中,它将自动将springSecurity/login重定向到https.

Add this entry to the web.xml which will automatically redirect the springSecurity/login to https.

<security-constraint>
    <web-resource-collection>
        <web-resource-name>secure</web-resource-name>
        <url-pattern>/springSecurity/login</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

这篇关于获取HTTPS的JSP页面的服务器名称和端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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