How to open JasperReports's report on Client Side [duplicate] - java

This question already has answers here:
JasperReports: How to call the report in jsp page
(6 answers)
Closed 6 years ago.
Im working in a Web application that allow the user to create and see the information from database with a JasperReports's report. The JasperReports works and I can see the copy in the server side.
The problem appears when I want to show the results to client in his computer.
The application send me a java.awt.HeadlessException because of AWT library that JasperReports use.
public void createView(){
jasperViewer = new JasperViewer (reportFilled);
jasperViewer.setVisible(true);
}
Its a very easy code, but I don't know how to fix this problem or its possible to use other libraries.
Some one can help me with other idea or know how to solve this?

This exception occurs only when you run a code in a non-awt environment such as servers. Take a look at link below about the solution.
How do I prevent a headless exception in Java?
If you want to run report in a server environment then show user in a web page you must convert to jasper print to html. take a look this answer for how to do that.
View report using JasperViewer or something else in web application

Related

Classnot found. Null Pointer exception when i wanna change .Jar to .exe [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 3 years ago.
I have created a java application to connect to a MySQL database. Once through the program install creator, I created a .exe .
This executable runs, and the first form is login. When he tries to access the database to confirm the details of login gives this error.
java.lang.NullPointerException
Someone can help me solve this? The path is correct because if run the .jar the application runs normally.
I apologize for the inconvenience.
enter image description here
Only have this to try to explain better my question :S
I'm so sorry... I'm running an executable version from my java application.
We will need more information than this, some things that you can provide that would be helpful are...
Your packaging tool (what you use to get from jar to exe)
Code
A stack trace

Check if system/computer has a display or graphical output available [duplicate]

This question already has answers here:
How to detect if a graphical interface is supported?
(5 answers)
Closed 8 years ago.
Update: as marked duplicate, I just want to mention, this seems like a duplicate, but the answer to the other mentioned question is not completely correct. Instead refer to the accepted answer below.
isHeadless would return unexpected true in certain cases.
Its a bit weird situation, but recently I build a very simple java application which can be run in console/terminal mode or in JavaFX UI mode.
However, then while using it on a remote computer which doesn't have any display attached. I got an error that this JavaFX UI application can't be initiated on systems without display, which is pretty obvious.
To overcome this problem, I have been looking for a robust way of detecting if the system has any display attached and it can initiate a JavaFX application, which has to be a platform independent solution, since it could be Windows or Ubuntu/Linux or Mac system.
Structure of the application:
A Main console app, which depending on input arguments executes internally a console app or UI app.
So that, if any arguments given, run in console mode or if no arguments then run in UI mode.
This is where I want to detect if there is a display available from within my main console app, which then won't even try to run the UI app if display is missing.
Any idea how can we achieve this or suggestion in a proper direction would be great.
I think you could use java.awt.GraphicsEnvironment
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
which will return an array with all the available screens. If this array is empty, there is no monitor.
Edit: About using isHeadless(), you can look at How to determine if GraphicsEnvironment exists

Is java code decompilable? [duplicate]

This question already has answers here:
How do I "decompile" Java class files? [closed]
(19 answers)
Closed 8 years ago.
I would like to know if Java code is decompilable? Because I am doing an app for Android and i'm wondering if using the mysql connector is safe or not?
Talking about the java code into an android application.
Thanks for your answers.
Your question is a nice example of the XY problem. It seems that you intend to, actually, have an android app use a database. Decompilation is the least of your worries. A user can use a packet sniffer to also get your authentication details in some cases. A simple strings foo.apk search can come up with the DB authentication details. Someone could hit your DB server from outside irrespective of your app;
A more viable solution would be to set up a web server that can handle untrusted requests and forward them to the database after filtering them. Then, you no longer have the risk of people stealing your DB credentials from the APK or device, since they no longer live there.

java.awt.AWTException: headless environment at java.awt.Robot.(Robot.java:94) [duplicate]

This question already has answers here:
Using HTML5/Canvas/JavaScript to take in-browser screenshots
(7 answers)
Closed 2 years ago.
I am doing screen recording application in servlet. But its working correctly in localhost with tomcat sever7x. But when I hosted in web server it shows error like this
java.awt.AWTException: headless environment at java.awt.Robot.(Robot.java:94)
Can any one help me? Thanks.
this is not clear to me,
are you trying to capture the server's screen?
as you are using servlet?!
i think its related to display issues on the server
because most servers does not have GUI (Gnome or desktop) as windows for example
so thats your problem
also have a look at this post
Headless environment error in java.awt.Robot class with MAC OS
last post by Ginger Head
This exception is happening because you're using some API that requires environment to support graphics (if saying that simplified). In order to resolve issue you have to either get rid of using classes that requires graphics support, or run it at not headless environment. Try taking a look at line 94 of Robot.java to find out what API complains on headless environment.
You may find these links useful:
What does "headless" mean?
http://www.oracle.com/technetwork/articles/javase/headless-136834.html
I got this problem while running Selenium test(configured to use remote server) on Jenkins. Solution for mwe was to start Xvfb Plugin before the job: https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin

How do I determine the default browser in Windows and Linux? [duplicate]

This question already has answers here:
Looking for a Java User Agent String Parser [closed]
(2 answers)
Open a link in browser with java button? [duplicate]
(7 answers)
Closed 10 years ago.
I am designing small Java application and there is a webDriver in it. The application will collect information from a web service.
One of the requirements for this app is no particular browser dependency. That is, I don't know which browser is installed on the end user PC. As a result, I need to use the default browser. How do I do this?
in Windows :you can use browse(URI uri) function in Desktop class ,it launches the default browser to display uri
Desktop.getDesktop().browse("/////URI");

Categories