Forums

Home » Liferay Portal » English » Liferay Legacy »

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Steve B S
how to set codebase attribute for loading applets from portlet war files
December 21, 2006 1:17 PM
Answer

Steve B S

Rank: New Member

Posts: 4

Join Date: November 10, 2006

Recent Posts

I've seen a few people run into this issue. If you have a JSP page which contains an applet HTML tag or a similar JSP tag to embed and applet, how do you set the codebase? The first thought most have(including myself) is to stick your applet jar file in the web app's WEB-INF/lib directory and attemot to use some varation of that path:

/myapp/WEB-INF/lib
myapp/WEB-INF/lib
/WEB-INF/lib
WEB-INF/lib

To understand why this will NOT work you need to understand what is happening behind the scenes. When the page loads in the user's browser an HTTP request is made to a servlet running which handles HTTP requests. Now, here is the important part... the servlet CAN'T serve files located underneath the WEB-INF directory. It is off limits. So while your relative URL specified in the codebase attribute may make perfect sense, the servlet will likely return an "access forbidden" HTTP header. The JRE in the user browser then interprets this incorrectly(since it's expecting an applet) and throws a wild exception complaining about a bad "magic number." Quickly, a magic number in Java land just is a way of distinguishing what the "type" of file is, e.g. a .class file, a .jar file, etc. In fact if you open up a .class file in a hex editor you can see the hex representation of the magic number for this type of file(which is humerously CAFEBABE).

But to get back on track... you simply need to move your .jar file outside of WEB-INF into... say... a directory called applet. So you would have myapp/applet/myjar.jar. The path you would specify in the codebase attribute would then be:

codebase="/myapp/applet"

Also, be sure to set the attribute:

archive="myjar.jar"

in the applet/object/jsp tag you're using.


When I first encountered my "problem" I though it had to do with liferay but it doesn't. This is simply how the JSP engine(at least for tomcat and likely others) works.

Hope this helps a bunch of people.
Udaya Ramakrishnan
RE: how to set codebase attribute for loading applets from portlet war file
November 15, 2011 11:39 PM
Answer

Udaya Ramakrishnan

Rank: Junior Member

Posts: 67

Join Date: September 6, 2011

Recent Posts

hi

i want to customize the jsp file "edit_user_portrait.jsp" that should include APPLET.
in the codebase: is myapp denotes the external application created apart from Liferay but deployed that in Liferay?
are u trying to make a call of external applet class into liferay via codebase.

thanks
Udaya.R
Udaya Ramakrishnan
RE: how to set codebase attribute for loading applets from portlet war file
November 25, 2011 5:18 AM
Answer

Udaya Ramakrishnan

Rank: Junior Member

Posts: 67

Join Date: September 6, 2011

Recent Posts

hi

I found the solution for adding applet in JSP page.
As a point of sharing i am telling the procedure:
Created a Dynamic web project that should include the Applet implementation
In the Jsp page that should run the applet include the line as below
<applet code="yourclass.class" codebase="<%=PortalUtil.getPortalURL(request)%>/webProjectname/anyfolder" archive="yourjar.jar" width="450" height="70"></applet
Now deploy the portlet/hook and also the dynamic web project


Thanks
Udaya.R