Java 如何将请求从servlet重定向到https

Java 如何将请求从servlet重定向到https,java,jsp,servlets,Java,Jsp,Servlets,我有一个网站,欢迎文件是一个servlet <welcome-file-list> <welcome-file>Main</welcome-file> </welcome-file-list> 主要 servlet从数据库收集数据并将其发送到JSP。如何将所有请求从主servlet重定向到https? 有什么想法吗??? 感谢感谢Eng.Fouad的提示。。。 问题解决 //Check if the requested scheme

我有一个网站,欢迎文件是一个servlet

<welcome-file-list>
    <welcome-file>Main</welcome-file>
 </welcome-file-list>

主要
servlet从数据库收集数据并将其发送到JSP。如何将所有请求从主servlet重定向到https? 有什么想法吗???
感谢感谢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);
}

感谢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);
}

谢谢你的提示。。。。我会更新答案。。这只是一个计划的问题。。。谢谢你的提示。。。。我会更新答案。。这只是一个计划的问题。。。谢谢