7 Replies Latest reply: Jun 3, 2012 6:43 PM by b noir
buckaroogirl Level 1 Level 1 (0 points)

Hello!

 

*********************************
Could you tell me why it happend?
Is it a bug with Safari 5.1.5?
*********************************

 

I found that JavaScript doesn't work correctly on Safari 5.1.5 (My MacOS is
10.7.3).

There are three simple src files in my webapp.
------
1. SafariTest.jsp
2. web.xml
3. SafariTest.java
------

 

My [SafariTest.jsp] is like below:
------
<html>
<head>
<%
String strFromFlag=(String)request.getAttribute("FromFlag");
%>
<script type="text/javascript">
function start()
{
  if ("FromServlet" == "<%= strFromFlag %>")
  {
    alert(document.frmSafari2.test1.value);
  }
  else
  {
    document.frmSafari1.submit();
  }
}
</script>
</head>
<body onLoad="start();">
<%
if ("FromServlet".equals(strFromFlag))
{
%>
<form name="frmSafari2">
<input type="hidden" name="test1" value="TestOK"/>
</form>
<%
} else {
%>
<form name="frmSafari1" method="POST" action="SafariTest.do">
<input type="hidden" name="test1" value="TestNG"/>
</form>
<%
}
%>
</body>
</html>
------

 

And [web.xml] is like below:
------
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Safari Test</servlet-name>
<servlet-class>com.example.web.SafariTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Safari Test</servlet-name>
<url-pattern>/SafariTest.do</url-pattern>
</servlet-mapping>
</web-app>
------

 

And [SafariTest.java] is like below:
------
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SafariTest extends HttpServlet {
  public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
  {
    request.setAttribute("FromFlag", "FromServlet");
    RequestDispatcher view = request.getRequestDispatcher("SafariTest.jsp");
    view.forward(request, response);
  }
}
------


Then I compiled SafariTest.java and put them into Tomcat 5.5.28's [webapps]
directory like below.
------
├─SafariTest                   SafariTest.jsp
│  └─WEB-INF                  web.xml
│      └─classes
│          └─com
│              └─example
│                  └─web      SafariTest.class
------
After I started Tomcat 5.5.28, and access
http://xxx.xxx.xxx.xxx/SafariTest/SafariTest.jsp via Safari 5.1.5,
I got the [TestNG] alerted.

 

I think [TestNG] is not the right result because with Firefox 3.6.13 or
Safari 5.1.3, I can get the [TestOK] alerted.

 

When access SafariTest.jsp directly, the FromFlag is null and thus submit to
SafariTest servlet. In SafariTest servlet, I only set the FromFlag to
[FromServlet] and forward to SafariTest.jsp once again. Now because of FromFlag
is [FromServlet], I think that [TestOK] will be alerted.

 

Yours sincerely.
Ye Qing
2012/05/08