开发者

What is the equivalent of JOptionPane in JSP?

I want to make such as JOptinonPane in JSP. What is the equivalent of i开发者_Go百科t JSP?


First of all, JSP runs at the webserver, produces HTML/CSS/JavaScript and sends it to webbrowser. Webbrowser retrieves HTML/CSS/JavaScript and interprets/applies/executes it. If Java/JSP has done its task right, the webbrowser should not retrieve any line of Java/JSP code. Simply because it doesn't understand it. Rightclick page and choose View Source. It'll become clear. Does it? :)

Now, in a webbrowser you can use JavaScript to show dialogs. E.g. an alert dialog with one button:

<script>alert('An alert message');</script>

A confirmation dialog with two buttons (which returns true or false depending on button pressed):

<script>var confirm = confirm('Are you sure?');</script>

A prompt dialog message with two buttons (which returns the input or nothing depending on button pressed):

<script>var input = prompt('Enter input', '');</script>

Just write it down in the JSP page the usual way. JSP will send it to the webbrowser.

See also:

  • W3schools JavaScript tutorial - popup boxes
  • Communication between Java/JSP/JSF and JavaScript

To get a step further, you can make use of more advanced JavaScript and a good shot of CSS in combination with a HTML <div> element to create a nice-looking dialog. You can find here some examples based on jQuery UI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜