我有一个网站,欢迎文件是servlet。
<welcome-file-list>
<welcome-file>Main</welcome-file>
</welcome-file-list>
servlet从数据库收集数据并将其发送到JSP。如何将所有请求从主servlet重定向到https? 任何的想法??? 感谢
答案 0 :(得分:3)
感谢 Eng.Fouad 提示...... 问题解决了
//Check if the requested scheme is http then redirect it to https
if(request.getScheme().equals("http"))
{
response.sendRedirect("https://www.mysite.com");
}
//If the request is not http but https then collect the data and send to jsp
else
{
//Collect the data from the database and send it to JSP
request.setAttribute("data",data);
RequestDispatcher rd = request.getRequestDispatcher("/main.jsp");
rd.forward(request, response);
}