2013-02-25 82 views
0

我有一個網站,其中歡迎文件是一個servlet。如何將請求重定向到https從一個servlet

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

該servlet從數據庫中收集數據並將其發送到JSP。我如何將所有請求重定向到主Servlet的https? 任何想法??? 感謝

+2

'的sendRedirect()'? – 2013-02-25 13:53:25

+0

感謝您的提示....我會更新答案..這只是getScheme的問題...謝謝 – 2013-02-25 14:13:18

回答

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); 
} 
相關問題