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>
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>
May 9th, 2007 at 12:08 pm
It is a nice example, please change the “ for ", please put more examples, with GUI
April 15th, 2009 at 4:18 am
asdfsdfsdfsdfsdfsd