看一下:server.xml的配置,https配置中加上:scheme="https"指定端口的访问协议是https,如果tomcat版本较老,可以在:web.xml配置指定的哪些网页需要https访问:<security-constraint>
      <web-resource-collection>
        <web-resource-name>HTTPSOnly</web-resource-name>
        <url-pattern>/admin_index.jsp</url-pattern>
        <url-pattern>/login.jsp</url-pattern>
      </web-resource-collection>
      <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
      </user-data-constraint>
</security-constraint>

解决方案 »

  1.   

    在server.xml中,port 8443的配置已经加入了scheme="https"。现在我的问题是如何让http协议访问8443端口时(http://localhost:8443),出现类似Bad Request You're speaking plain HTTP to an SSL-enabled server port.这种信息。
      

  2.   


    最笨的办法:在web.xml中增加过滤器:
    <!-- 设置过滤器 统计文件下载次数  --> 
    <filter>
       <filter-name>fileDownNum</filter-name>
       <filter-class>org.xxx.filter.FileYouClass</filter-class>
      </filter>
      <filter-mapping>
       <filter-name>fileDownNum</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>  在:.FileYouClass中,从request中获取访问的协议是http还是https,然后返回给用户页面就好了
      

  3.   

    使用了Filter的方法,发现在doFilter()中,通过ServletRequest对象来获取request的信息,发现无论是https://localhost:8443,还是http://localhost:8443,得到的scheme都是https。而且还发现这个问题跟session有关系,当https://localhost:8443访问成功后,立即将URL改成http://localhost:8443,网页仍能访问。似乎当前session仍认为是在使用https://localhost:8443。 但如果不操作页面了,当目前的session不存在后,再使用http://localhost:8443,就只能显示空白页面了。这是Tomcat的问题吗?