NPE NPE - 3 months ago 35
Java Question

JOptionPane.showMessageDialog on Java Platform Enterprise Edition (JSP)

I just wanted to know can we use

JOptionPane.showMessageDialog
in Java Server Page(*.JSP) like
MsgBox("Message")
in ASP.NET?

I have tried this code

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.swing.JOptionPane"%>

<%
JOptionPane.showMessageDialog(null, "Message");
%>


and I got this :

HTTP Status 500 - Internal Server Error

Answer

This is not possible as calling JOptionPane.showMessageDialog requires the following params

public static void showMessageDialog(Component parentComponent,
                 Object message)
                          throws HeadlessException

Brings up an information-message dialog titled "Message".

Parameters:
    parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used
    message - the Object to display

The parent component here should be valid subclass of Component class or in layman terms some kind of swing or awt frame.Which JSP won't be able to provide.