2014-01-17 54 views
0

我只想知道我們可以在ASP.NET服務器頁面(*。JSP)中使用JOptionPane.showMessageDialogMsgBox("Message")嗎?Java平臺企業版(JSP)上的JOptionPane.showMessageDialog

我已經試過這個代碼

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

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

,我得到這個:

HTTP Status 500 - Internal Server Error 
+0

簡單,你不能這樣做。你爲什麼不使用Javascript的警報? –

+0

heyy,謝謝你的迴應。我只是想知道:) – NPE

回答

2

這是不可能的,因爲調用JOptionPane.showMessageDialog需要以下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 

這裏的父組件應該是組件類的某種搖擺或AWT frame.Which JSP贏得或通俗地說有效小類無法提供。

0

你混合桌面技術與網絡。這是不可能的

+0

哈哈,謝謝。我只是想知道。像.Net技術一樣,我們仍然可以在他們的網絡技術中使用MsgBox。 – NPE

-1

這是不可能的,
改爲使用javascript alert

0

是的,這可能與jdk1.7
看到這個JSP文件:

<% 
    String msg = request.getParameter("msg"); 
    if (msg == "") 
     JOptionPane.showMessageDialog(null,"name cannot be blank "+msg); 
    if (msg != null) 
      JOptionPane.showMessageDialog(null,"Welcome "+msg); 
%> 
<form name='form'> 
    Enter name <input name='msg'> <br> 
    <input type="button" value="ok"> 
</form>