Using a Java applet in a SharePoint web part
I have a need to integrate a third-party Java applet into a custom web part I wrote for SharePoint 2007. The web part simply loads a user control I created that contains the bulk of the functionality, and that's where the applet will go. I added it to my user control project and it works fine outside of my SharePoint environment.
I installed the updated web part onto my MOSS 2007 development site and the part's page loads fine. The applet is triggered by clicking a link button on the page, which runs some client-side JavaScript to start it. The problem is nothing seems to happen when I click the link. No error messages appear, and the stuff the applet is supposed to do never occurs (it's for doing file transfers via FTP). I have the .jar file as an embedded resource in my user control DLL, which is deployed to the bin folder, and SharePoint fully trusts this DLL.
I used Firebug to step through the initialization code and I saw an HTTP GET that failed with a message about not being authorized, but it didn't give any details and I'm not positive it was related to the applet.
Is there anything special I need to do to make the apple开发者_运维问答t work? Or am I going about this the wrong way?
EDIT: The problem turned out to be the .jar file for the applet couldn't be found. SharePoint is clearly doing something different here, and I need to find out what. Can Java applets be used within a SharePoint site? This question suggests they can, but in that case a Page Viewer web part was used, which isn't going to really work for me.
An applet in HTML is handled by applet/object tag. Your webpart should just render the OBJECT/applet tag and its attributes relevant to the applet (code, height, width) or you can let the JavaScript do it all and your webpart can provide the marker div where the applet needs to be rendered. That's about it and Sharepoint does not have to have any more knowledge about the applet since it is all taken care of the browser. The archive parameter points to the jar that can be located on your server than should be browsable. Instead of bundling it as a resource in the DLL , host it on the server just outside of the Sharepoint website. You might have to create a virtual directory in a different website for the same. This simplifies the deployment model.
It is possible the applet make a HTTP call back to the SharePoint site and it does not pass any credentials
精彩评论