developers

    Forum Stats

  • 3,874,062 Users
  • 2,266,667 Discussions
  • 7,911,709 Comments

Discussions

Clueless on request.getContextPath()

859702
859702 Member Posts: 4
Hi, I am invoking the applet in a jsp as shown

<%
String contextPath=request.getContextPath();
%>


<APPLET CODE = "EmbeddedViewerApplet.class" CODEBASE = "<%=contextPath%>/applets" ARCHIVE = "ReportApplet.jar" WIDTH = "100%" HEIGHT = "90%"></XMP>
<PARAM NAME = CODE VALUE = "EmbeddedViewerApplet.class" >
<PARAM NAME = CODEBASE VALUE = "<%=contextPath%>/applets" >
<PARAM NAME = ARCHIVE VALUE = "ReportApplet.jar" >

<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">
<PARAM NAME="scriptable" VALUE="false">
<PARAM NAME = "REPORT_URL" VALUE ="<%=contextPath%>/GetJasperPrintObject">

</APPLET>


My server is running at the instance/context http://server/a/b where b is the context name

However, When I see the rendered HTML, the contextPath is printed with difference

At first line, it rendered /a/b/applets
At subsequent lines, it just printed /b/applets and /b/GetJasperPrintObject


Can you guys help in finding the error/problem with the code? Why is that the request.getContextPath() iis printing differently at different places?

Answers

  • EJP
    EJP Member Posts: 32,924 Gold Crown
    That's not a correct description. The question is why is a variable rendering differently in different places. Where the value came from isn't actually relevant.

    I suggest you have a look at the generated Java code.
  • 859702
    859702 Member Posts: 4
    Yes, you are right.

    But why does the same variable is rendering differently at different places?

    I printed the variable at each place using System.out.println, it printed same for three places. Yet, in generated HTML, it is different.

    Is this related to <applet> and <param> tag?
  • EJP
    EJP Member Posts: 32,924 Gold Crown
    The applet/param tags shouldn't have anything to do with it. What does the generated source code look like?
  • 859702
    859702 Member Posts: 4
    Generated source is like this....

    <APPLET CODE = "EmbeddedViewerApplet.class" CODEBASE = "/a/b/applets" ARCHIVE = "ReportApplet.jar" WIDTH = "100%" HEIGHT = "90%"></XMP>
    <PARAM NAME = CODE VALUE = "EmbeddedViewerApplet.class" >
    <PARAM NAME = CODEBASE VALUE = "/b/applets" >
    <PARAM NAME = ARCHIVE VALUE = "ReportApplet.jar" >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2">
    <PARAM NAME="scriptable" VALUE="false">
    <PARAM NAME = "REPORT_URL" VALUE ="/b/GetJasperPrintObject">
    </APPLET>
  • EJP
    EJP Member Posts: 32,924 Gold Crown
    No it isn't. That's the XHTML. I'm talking about the Java code.
  • User_64CKJ
    User_64CKJ Member Posts: 7,279 Silver Badge
    856699 wrote:
    Generated source is like this....

    <APPLET CODE = "EmbeddedViewerApplet.class" CODEBASE = "/a/b/applets" ARCHIVE = "ReportApplet.jar" WIDTH = "100%" HEIGHT = "90%"></XMP>
    What is the <tt></XMP></tt> doing in there?
This discussion has been closed.
developers