Serve up a Java Applet with Laravel - java

I'm trying to wrap my mind around how to deploy a Java applet in my Laravel app.
To start with I'm just going to keep it simple and use the applet tag in a view:
<applet code="OHLib.class" width=0 height=0 />
(The applet contains just helper functions ... no UI, so I set width and height to 0. Will that work?)
When the browser requests that class from my web site, how to I serve it up? Do I define a route? I would like the java class to be located at www.mydomain.com/java/OHLib.class.

Deploy An Applet
Applets are deployed onto a web page via certain tags, which vary by browser, so the best thing to do is use a script provided by Oracle to inject the correct tag for you. I put the following code in a View so as to appear within the <body> tag. (It won't work in the <head> section.)
<script src="https://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {
id:'ohApplet',
code:'OHLib',
codebase: 'java',
archive: 'OHLib.jar',
width:1,
height:1,
} ;
var parameters = {
jnlp_href: 'OHLib.jnlp',
classloader_cache: 'false',
} ;
deployJava.runApplet(attributes, parameters, '1.6');
</script>
This will cause the browser to load OHLib.jar from the java folder. If the .jar file is in the same folder as the HTML document, you can skip the codebase attribute. See Deploying a Java Applet.
Serve An Applet
When the browser parses the injected tag, it will then make a request to the server for the Java applet, based on the 'archive' and 'codebase' attributes. So in my case I created a folder called 'java' under the Public folder, and placed the .jar file in there. Remember that your web app only gets invoked for URIs that don't exist on the server file system.

Related

JSP file not using CSS because of web.xml

I've had this simple jsp log-in form that used the css style sheet. It was working just fine until I included the web.xml file in my directory. Now the JSP file won't load the css files no matter what. I've tried changing the link address of the css in multiple different ways but with no luck.
I'm pretty positive that the web.xml file is the reason it's not loading because if I remove it, everything works again.
Here's my project structure:
Here's my login.jsp:
here's my web.xml:
Your web.xml includes /* in a security constraint, limiting access to all content of your application to those users with the role users. This means that, instead of serving your CSS file as requested to the browser, tomcat will redirect to the login.jsp as well (which is obviously an incorrect and not very stylish stylesheet)

Common Error Page for All Directories in Java Web App

I am trying to have a error.html error page in my Java WebApp with web.xml entry as below:
<error-page>
<location>/error.html</location>
</error-page>
having a directory listing as:
--App
-- index.html
-- error.html
-- css/
-- ...
-- js/
-- ...
-- img/
-- ...
-- folder/
-- index.html
When I enter an address say:
/App/some-wrong-address or /App/folder/some-wrong-address
In both the cases I am able to see the Error Page called in as part of 404 error, but in latter case I am not getting my resources like caa, js, or img pulled up.
I understand that the resources are called relatively with ./... path and in the second case it is expecting it to be ../... because of directory change, but I want to OVERCOME this thing, I am not directly working on production server and I cannot use exact URL of everything with localhost as it will have to change later everywhere.
Let me know how can I do this?
I am using Tomcat 8.0.28 and WebApp version is 3.1.
The key is to correctly produce all of the HTML that your webapp produces. The HTML must have the correct URLs (note: they are URLs, not paths) in the elements that refer to other assets (CSS, images, javascript).
You are correct that putting the absolute URL of your production system in your source files is not a workable solution.
In a JavaEE web app I worked on, we used JSF Facelets as the templating system for producing our HTML. In that we wrote each URL like this:
<script src="#{request.contextPath}/foo/bar/baz.js" />
<img src="#{request.contextPath}/img/something.png" />
This allows any template, at any location in the URL hierarchy, to reference any asset. The JavaEE app server handles filling in the correct context path so that the resulting URL the browser handles is correct regardless of where it is hosted.
application.getContextPath() will give you page context,and you can base ur urls accordingly after that..will work on local server as well as deplyment server..
e.g: ... href=" <%=application.getContextPath()%>/css/yourcss.css" ... etc.
N.B.: its a good idea to design your error page in a way that it as no dependencies to any other files..styling and resources in that case should be absolute or inline and images if any should reside in the same folder as your error page

Specifying a jQuery mobile main page

Given a jQuery Mobile app with several pages
Home.html > Profile.html > Registration.html > ...
How do i set up my app so Home is the page that loads first and is presented to the user when they launch the app on their mobile?
It depends on what are you doing.
If you are creating a basic mobile web page that this depends on your web server. If you are working with Apache web server you would change httpd.conf and replace this:
DirectoryIndex index.html
with this:
DirectoryIndex index.html main.html
Or if you don't have access to your web server you would create a .htaccess in your project directory and do same thing as above. Read more about it here.
On the other hand, if you are working with Phonegap then all you need to do is change location Phonegap looks for app initialization.
This is Android example:
super.loadUrl("file:///android_asset/www/main.html");
Read more about it here.
But you should stick to standards and rename main file to index.html
iOS is little bit different, unlike Android, you need to change some configurations thus forcing iOS to load different file then index.html.
In Classes folder open AppDelegate.m and change this:
self.viewController.startPage = #"index.html";
to this:
self.viewController.startPage = #"main.html";

Deploy JNLP applet *without* Next Gen Java Plugin

I need to deploy an applet on a .jsp page and want to take advantage of lazy loading and pack200 that you get when using JNLP. However my client does not have the Next Gen Java Plugin enabled on their machines and they do not want to enable it. This means I can not take advantage of the jnlp_href attribute introduced in java 1.6.10.
After some research I discovered you can specify an applet-desc in my jnlp but I am new to JNLP and do not know how to fully take advantage of this tag.
I have not seen any solid examples of how to use a JNLP file on a webpage without using the applet or object tags which require the jnlp_href param attribute.
Is it possible using this applet-desc tag to inject a reference to my JNLP in my .jsp page?
Currently I specify my applet using the object HTML element like this:
<object code="<myappletClass>" name="pdfapplet" codebase="<myCodeBase>" mayscript>
<param name="jnlp_href" value="my-applet.jnlp"/>
</object>
However this does not grab the jnlp_href with Java plugin turned off in the Java console.
If the applet does not need to be embedded in the web page, it can be launched free-floating from the first versions of Java Web Start (available as a separate download around Java 1.2). It is only in the Next Generation JRE that a JWS deployed applet can remain embedded in a web page.

Servlet Generated Web Pages Finding Images Inside Of A *.war?

I'm maintaining a legacy Java servlet webapp ( nwp ). My goal is to learn Spring and gradually update the webapp to use Spring as much as possible.
The servlet webapp, nwp, now runs on WebLogic 9.2. It is packaged and deployed as nwp.war. Every HTTP Request gets submitted to a unique servlet, which process the request and prints out a web page/screen. Each servlet will read in various resource files from a remote location outside of nwp.war to use for headers, footers, etc.
Yes, it is primative, which is why I want to update it. It also made sense to have the "include files" in a remote location outside of the war as 3 applications use those files. However, as part of updating the nwp app I plan on consolidating the other two ( similarly primative ) apps into just the nwp. Eventually.
As a first step in converting this application to Spring I have rearranged the directory tree to have these subdirectories under the WEB-INF dir:
images
js
css
The servlet generated HTML references images as
"
My problem is that right now the servlet generated HTML can not find images in the WEB-INF/images directory inside of the nwp.war.
Right now, the nwp.war file contains a file called weblogic.xml to map the URLs for images to where they sit on the server:
<wls:virtual-directory-mapping>
<wls:local-path>/common/resources/images</wls:local-path>
<wls:url-pattern>/images/*</wls:url-pattern>
<wls:url-pattern>*.jpg</wls:url-pattern>
<wls:url-pattern>*.gif</wls:url-pattern>
</wls:virtual-directory-mapping>
I'm new to WebLogic and WebLogic 9.2.
I've tried changing that mapping in a number of was so that the servlet generated HTML will look for the pictures in the WEB-INF/images directory inside of the war.
Is this (servlet generated html finding images ) even possible or am I going to have to use the current system of getting images until I can convert the servlets into JSPs?
Thanks
Steve
The HTML won't be able to directly reference images inside the WEB-INF folder. This is for security. So you have 2 options:
Move the images so that they're directly under / rather than /WEB-INF/
Create another servlet to serve those images
If you decide to use a servlet, you can use ServletContext getResourceAsStream to access images from the /WEB-INF/images directory. For example:
servletContext.getResourceAsStream("/WEB-INF/images/test.jpg");

Categories