简体   繁体   中英

Show Questions to Users server-side [Java]

I learned that I cannot use JOptionPane on server (sigh). Now the simple question is:

What I can use instead of JOptionPane, to show messages to clients and have a response (fe Yes, No, Cancel) in a Java-servlet?

I cannot use Javascript alert message in client-side (.jsp pages) because I need first to do some operations server side.

Please, don't tell me it's impossible!

What I would like to do is

/*JAVA CODE*/
if (some conditions)
{
    int i = JOptionPane.showConfirmDialog(null,"Question","?", JOptionPane.YES_NO_OPTION);
    if ( i == 1)
       /*DO SOMETHING*/
    else
       /*another message*/
       int j = JOptionPane.showConfirmDialog(null,"Question 2","?", JOptionPane.YES_NO_OPTION);
}
 /*JAVA CODE*/

I read that exists Rhino ( https://developer.mozilla.org/en-US/docs/Rhino/Examples ) but I don't know if it's ok for my needs.

Unless you use applets you cannot use Swing in webpages.

You will need to use HTML or another technology used in browser to do what you need. There are many frameworks above raw HTML allowing to invoke code server side when clicking links or buttons before the target page is shown. Which one to use depends on which environment you are using and what technologies you have available to you.

Note, that good webapplications require programming two places. The server and the client, and they can be rather different. You may want to open a new question asking how you can do what you need to do in the environment you have chosen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM