Reputation: 215
When deploying my .war file on the fixed IP application server on Tomcat 7 everything works until the following class is initialized. Can the server not detect the resolution of clients browser or just a simpler reason?
@SessionScoped
@ManagedBean(name = "Resolution")
public class Resolution implements Serializable {
private static final long serialVersionUID = -3843115933315030209L;
GraphicsDevice gd;
double screenWidth;
double screenHeight;
{
gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
setScreenWidth(gd.getDisplayMode().getWidth() * .85);
setScreenHeight(gd.getDisplayMode().getHeight() * .85);
System.out.println(screenHeight);
System.out.println(screenWidth);
}
}
with that exception thrown:
javax.servlet.ServletException: Klasse de.kp.screen.Resolution kann nicht instanziiert werden.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
Upvotes: 0
Views: 70
Reputation: 34638
No. The servlet is running on the server machine, and the browser is running on the client machine. They are two separate computers.
The browser communicates with the servlet by sending requests through an HTTP connection, and the servlet can then respond to these requests by sending back HTML or other data.
To detect things like window size, you need to present an HTML to the user that contains Javascript code. Javascript runs on the client machine, inside the browser. That Javascript code can then call your server back with the information it needs.
To change window size, you also need to use Javascript that will run on the client side.
All of the Java GUI components are intended for programs that run directly on the user's desktop (or Android gadget). They usually can't be used in a server machine at all, because a server doesn't always have a Graphical user interface (you connect to it via a text console).
Upvotes: 2