HTTP-сессии не работают на iOS для всех браузеров - PullRequest
0 голосов
/ 28 мая 2018

Мой веб-сайт работает нормально во всех браузерах для устройств Windows и Android.Но java-сессии возвращают нулевые значения на страницах JSP, когда дело касается устройств iOS для всех браузеров.

testinput.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="testing" method="post">
    <input type="text" name="pdf1">
    <input type="text" name="pdf2">
    <button type="submit">click me</button>
</form>
</body>
</html>

testing.java (сервлет) :

import java.io.IOException; 
import javax.servlet.ServletException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.Cookie; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession;

/**  * Servlet implementation class testing  */ @WebServlet("/testing") 

public class testing extends HttpServlet {  
private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public testing() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**      
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)   
*/  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {       
// TODO Auto-generated method stub      
response.getWriter().append("Served at: ").append(request.getContextPath());    }


/**      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */     
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      
String abc = request.getParameter("pdf1").toString();       
String def = request.getParameter("pdf2").toString();

HttpSession sess = request.getSession();        
sess.setAttribute("pdf1", abc);         
sess.setAttribute("pdf2", def);         
if(sess.getAttribute("pdf1")!=null){            
Cookie cook = new Cookie("login", sess.getAttribute("pdf1").toString());             

response.addCookie(cook);       
}       
response.sendRedirect("test.jsp");      
return;     
}
}

test.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%try{ %>
    <% Cookie cook[] = request.getCookies();

    for(Cookie c :cook){
        if(c.getName().equals("pdf1")){
            String str = c.getValue();%>
            <p><%=str%></p> 
        <%}
    }%>     
    <p><%=session.getAttribute("pdf1").toString() %></p>
    <p><%=session.getAttribute("pdf2").toString() %></p>
    <%}catch (Exception e){ 
        e.printStackTrace();
        log("erroristhis"+e);
        }%>
</body>
</html>

Apache :

Я добавил следующие строки в свой https.conf.virtualHost*:80 файлы на моем Linux-сервере VPS для доступа к переменным сеанса.

<VirtualHost *:80>
ServerName example.com
ServerAlias mail.example.com www.example.com
#  DocumentRoot /home/example1/public_html
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
JkMount  /* example
<Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPass               /       http://localhost:8080/example/
  ProxyPassReverse        /       http://localhost:8080/example/
  ProxyPassReverseCookiePath        /   domine/
</VirtualHost>
...