My website is working fine in all browsers for Windows and Android devices. But java sessions are returning null values on JSP pages when it comes to iOS devices for all browsers.
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:
I added below lines to my https.conf
. virtualHost*:80
files in my linux vps server to access session variables.
<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>