For context, I developed a web application using JS & HTML that allows a user to manually upload a log file (from a shared folder on a Tomcat server) and display errors, info, etc based on the format of the log file.
However, say I want to cut the user upload, and automatically retrieve files from the Tomcat server (running on an Apache instance - so web app would be deployed on the Apache box) and then display the information on a web page - would I need to use a java servlet, or could I use php with js? I doubt that I could do it server-side with JS? Any advice?
Yes, you'd need something on the server side (e.g a java servlet, a php page) to grab the content from the server and make it available to client side (e.g html+js).
Related
I have a fully functional java application(with .jar extension) that can be hosted on a server.
I have a front end website(php) that needs to accesses that application and provide the resultant data that comes out of the application.
What is the best way to do that ? Or am I missing some logic in here?
as of now the app is built as a mac application with a GUI interface where the user has to get the application installed on their workstation. Thus, deciding to move the app to server and provide an unique website where the frontend can access the app hosted on the server
You need to turn your java application to rest service, if you want to get data from java application for your frontend application. If your app's architecture is well design it will not be a big deal.
If you already have a front-end site running PHP, you are likely either running apache or nginx.
Using either, you can configure a proxy for a specific URL, to be forwarded to the application, i.e.
curl http://example.com
> serve /www/example.com/index.php
curl http://example.com/api/abc
> serve http://127.0.0.1:8080/abc
In your apache config file, assuming that once started, your jar file binds to port 8080.
ProxyPass /api http://127.0.0.1:8080/
ProxyPassReverse /api http://127.0.0.1:8080/
I'm researching using JSP for a project that could be accessed locally and over the web. That is, I would be creating the project in JSP and would like to generate a kind of setup.exe that the client would run to set up the environment to run the JSP in their browser. For example, if I were to choose Tomcat, do I create a setup program that also installs Tomcat and then stores the JSP application in the proper directory? More specially, for those in the industry that program JSP professionally, how does your company deploy a JSP application to the client? If you host the JSP application on your server what about a solution where the client hosts a local server so they can run the application locally on their machine? Is that possible?
I think you have some confusion. In a JSP-based application (note that that technology is very old and you should use JSF instead) there are two sides: the server side and the client side.
The server side has Tomcat or any other Web Application Server that
deploys the JSPs as you said.
The client side just needs a browser (e.g. Mozilla, Chrome, Lynx,
etc) to access the JSP-based application via Web.
In other words, you don't deploy in client machines. You just deploy in the server and your clients access your application with, normally, a Web browser.
Further reading:
Java JSP, JSF and JS.
Difference between JSF sevlet and JSP
Well,I'm working on an Eclipse Dynamic Web Project under Tomcat.
I'm trying to make a web application/site.In a jsp/html page,there is a form where a user can upload a photo.
I handle then this action from a servlet that has to store this image/file somewhere so as to make it possible the image appears whenever I want on the site.
Here is the problem.I started by storing it on my file system,(path in a database) but when I wanted to retrieve it the page didn't appear.
I guess the reason is here:
Why can't I do <img src="C:/localfile.jpg">?
Then,I tried to store the file in the eclipse project folder(WebContent/folder) where I've stored manually some images that do appear.
File folder=new File("/TED/res/img");
File file=new File(folder,fileName);
System.out.println(file.toPath());
Files.copy(fileContent, file.toPath());
But this exception happens:
java.nio.file.NoSuchFileException: /TED/res/img/2017-08-13-123524.jpg
It's one the line of files.copy command which means that
new File(folder,fileName) that I tried failed
What should I do? From what I've read,I understood that also saving file in the IDE's project folder is also wrong but what other choice do I have?
Ultimately, the project will be deployed to a server. As such, there are three distinct issues:
Uploaded user content location: content like images should be uploaded to a folder outside your web app (project). Images inside the web app (project) should be those that are necessary for the application and provided by the developer, not user-generated.
In Eclipse, during development and testing, you will want to serve these images through Tomcat. There are many ways to do this. Tomcat configuration is probably not the best for this - please read the answer and discussion here: Simplest way to serve static data from outside the application server in a Java web application
Once the application is deployed to the server, Tomcat will most likely run behind a Web server like Apache or Nginx. In this case, the external image folder and its contained files can be served directly by the Web server. Even if you implemented a servlet in (2) for local testing with Eclipse and this servlet is part of the code that is deployed, it will not be invoked as the URL will be intercepted by the Web server before it reaches Tomcat. For example, if your uploaded image folder is C:\images on your development environment, it can be served by the servlet using the technique in (2) as /images/*. When deployed to a server, the Web server can be configured to servet /images/* from /srv/content/images and this request will never reach Tomcat.
I have a Java EE application, running under WebLogic 10.3.5 and Java 6.
I used to have a pdf help file, embedded in my war file, but I need to extract it from there and put it in an external directory (it can be in my same WebLogic domain directory).
I tried to put it in my WebLogic domain and then to < a href > it, but it seems that browsers have limitation and for security reason will not allow to download local file with a href or javascript.
This used to work only on a static HTML file saved on my computer but one the HTML page is deployed on the server, it seems not be possible.
Any idea how I can externalize my help.pdf file from my war file?
#limc is right
you should put this static file outside of Weblogic altogether as a file on an Apache web server
However, in Weblogic there is a feature of virtual directory mapping which allows you to declare a folder outside of the weblogic domain as a content store for any static stuff.
http://docs.oracle.com/cd/E11035_01/wls100/webapp/weblogic_xml.html#wp1039396
This entry goes in WEB-INF/weblogic.xml
<virtual-directory-mapping>
<local-path>c:/usr/mypdfs</local-path>
<url-pattern>/pdf/*</url-pattern>
</virtual-directory-mapping>
Although some application servers allow a Java EE app to reference a file outside the web container, in reality, your web app shouldn't have any knowledge about anything outside the web container, and as you have mentioned, it is indeed a huge security concern.
Depending on what you are trying to accomplish with this PDF file, if you merely want to expose this file on the web, do what #duffmo said and it will work fine. If you want the flexibility to modify this PDF file frequently without recreating the war file again and again, you may want to consider hosting this PDF file in some HTTP web server (Apache2, IIS, etc) and now you reference that link from your web app.
You need to put it at the root of your web context, in exactly the same place as HTML pages. Your web server will be able to find it there.
Now I have two .jar files: one is a chat Client and the other one is the chat Server. They are running fine on my desktop application, but now I want to upload them to run on my website. What is the best method for doing this? I have the following files:
chatclient.jar
chatserver.jar
Can some one please advise on how to put them in my web page without having to download them when a user clicks on them?
You do not provide enough information.
What would you like to achieve?
What technologies are you using inside the JARS?
Why not package the server jar with a web application ?
Is your client a desktop application, if so, why not to put it in the client's classpath?
Maybe consider having the client implemented in JavaScript using jQuery for example and some web sockets technology,
or maybe using some java web framework or tookit like GWT or Apache Wicket?