public class MyAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
String status="success";
HttpSession session = request.getSession(true);
System.out.println("My Action---setting key value");
request.getSession().setAttribute("key1","check");
//response.sendRedirect("http://localhost:9080/FamiliarPortal/jsp/inicio.jsp");
return mapping.findForward(status);
}
}
In Struts-config.xml
, the following is added:
<action path="/myAction" type="iusa.ubicacel.actions.MyAction" validate="false" >
<forward name="success" path="/jsp/inicio.jsp"/>
</action>
In web.xml
, the following is added:
<servlet>
<servlet-name>GetFAP</servlet-name>
<servlet-class>iusa.ubicacel.actions.map.GetFAP</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetFAP</servlet-name>
<url-pattern>/GetFAP</url-pattern>
</servlet-mapping>
In inicio.jsp
, the following is added:
<BODY onload="requestXML('<%=reqURL %>');">
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="middle">
<div id="mapdiv" style="width: 1000px; height:700px"></div>
</td>
</tr>
</table>
</BODY>
The function requestXML
is as follows:
function requestXML(reqURL)
{
alert("calling requestXML"+reqURL);
var url = "../GetFAP?requestURL=" + reqURL;
alert("calling requestXML"+url);
xmlhttpUbi = FAPXMLHttpRequest();
xmlhttpUbi.open("POST", url, true); // async
alert("after calling");
xmlhttpUbi.onreadystatechange = obtainFAPLocation;
xmlhttpUbi.send(null);
}
The above code is not calling the GetFAP servlet when using mapping.findForward
. But when I used response.sendRedirect("entire jsp path")
it is calling the servlet.
Can anyone tell me what I am doing wrong here?
public class MyAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
String status="success";
HttpSession session = request.getSession(true);
System.out.println("My Action---setting key value");
request.getSession().setAttribute("key1","check");
//response.sendRedirect("http://localhost:9080/FamiliarPortal/jsp/inicio.jsp");
return mapping.findForward(status);
}
}
In Struts-config.xml
, the following is added:
<action path="/myAction" type="iusa.ubicacel.actions.MyAction" validate="false" >
<forward name="success" path="/jsp/inicio.jsp"/>
</action>
In web.xml
, the following is added:
<servlet>
<servlet-name>GetFAP</servlet-name>
<servlet-class>iusa.ubicacel.actions.map.GetFAP</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetFAP</servlet-name>
<url-pattern>/GetFAP</url-pattern>
</servlet-mapping>
In inicio.jsp
, the following is added:
<BODY onload="requestXML('<%=reqURL %>');">
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="middle">
<div id="mapdiv" style="width: 1000px; height:700px"></div>
</td>
</tr>
</table>
</BODY>
The function requestXML
is as follows:
function requestXML(reqURL)
{
alert("calling requestXML"+reqURL);
var url = "../GetFAP?requestURL=" + reqURL;
alert("calling requestXML"+url);
xmlhttpUbi = FAPXMLHttpRequest();
xmlhttpUbi.open("POST", url, true); // async
alert("after calling");
xmlhttpUbi.onreadystatechange = obtainFAPLocation;
xmlhttpUbi.send(null);
}
The above code is not calling the GetFAP servlet when using mapping.findForward
. But when I used response.sendRedirect("entire jsp path")
it is calling the servlet.
Can anyone tell me what I am doing wrong here?
Share Improve this question edited Jul 16, 2013 at 12:38 user2473430 asked Jul 16, 2013 at 12:26 user2473430user2473430 431 gold badge2 silver badges8 bronze badges 4- 1 The forward you show has nothing to do with "GetFAP", I don't know why you'd think it would. – Dave Newton Commented Jul 16, 2013 at 12:29
- the forward is mapped to inicio.jsp in struts-config.xml.Onload of incio.jsp calls requestXML() function which calls GetFAP – user2473430 Commented Jul 16, 2013 at 12:32
- Then the problem is likely your use of a relative URL, but it's difficult to say. You can debug this, you know, by using the browser's debugging tools. – Dave Newton Commented Jul 16, 2013 at 14:43
- Yes.When I changed it to " var url = "GetFAP?requestURL=" + reqURL;" it worked.But I really don't understand why.The same thing worked when I didnt use Struts.What could be the reason?Also what would be the difference between "./GetFap" and "../GetFap" ? – user2473430 Commented Jul 16, 2013 at 16:12
1 Answer
Reset to default 1You are using a relative URL instead of an absolute URL.
When you render the JSP directly, the ../GetFAP
mapping works because you must move "up" a level up from the /jsp
directory.1
When you render the JSP from an action, you're moving a level up from the action's path, i.e., there's no more /jsp
directory in the URL to move up from.
This is among the many reasons why using relative paths can be a bad idea.
1 JSP files should live in the WEB-INF
directory to avoid direct client access.