对于所有浏览器,HTTP会话无法在iOS上运行

时间:2018-05-28 01:32:30

标签: ios linux jsp tomcat godaddy-api

我的网站在Windows和Android设备的所有浏览器中都运行良好。但是当涉及到所有浏览器的iOS设备时,java会话在JSP页面上返回空值。

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(servlet)

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。我的linux vps服务器中的virtualHost*:80个文件用于访问会话变量。

<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>

0 个答案:

没有答案