Java JSP - Simple JSP Example Example

This example illustrates how to write a simple JavaServer Page. Here we implement a game of Craps:

1. Roll two dice
2. If the sum of the two is 7 or 11, you win

<%
int dice1 = (int)(6*Math.random()+1);
int dice2 = (int)(6*Math.random()+1);
int total = dice1 + dice2;
boolean win;
if( total==7 || total==11 )
        win = true;
else
        win = false;
%>
<html>
<body>
you rolled: <%= dice1 %> and <%= dice2 %>
so you <% if (win)  out.println("win"); else out.println("lose"); %>
</body>
</html>

2 Responses to “Java JSP - Simple JSP Example Example”

  1. Alberto Larios Says:

    It is a nice example, please change the “ for ", please put more examples, with GUI

  2. recep Says:

    asdfsdfsdfsdfsdfsd

Leave a Reply