Search code examples
javajspstruts-1

How to set the value of context in the object tag of a jsp with struts 1


I need to know how to establish, in full context object tag of a jsp, because I'm getting fixed data, the jsp code is as follows:

<object type="application/pdf" data="http://localhost:8080/JasperStruts/report.do?dispatch=reports" width="80%" height="650"></object>

But instead of appearing "http: //localhost:8080/" i need appears according to where the application is run, the link is within the same system that is running.

i am using Struts 1

thanks


Solution

  • The data about path always are in the request, then you have to call request.getContextPath, in your case, the code would be something like this:

    <object type="application/pdf" data="<%=request.getContextPath()%>/JasperStruts/report.do?dispatch=reports" width="80%" height="650"></object>
    

    See this:

    http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getContextPath%28%29

    I hope this information help you.

    Good luck =D