Advertisement
Shavit

JSP1

Jan 22nd, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.08 KB | None | 0 0
  1. <!--Shavit Borisov-->
  2. <!--15.1.15-->
  3. <!--http://pastebin.com/GXVCpgu4-->
  4.  
  5. <%@ page language="java" contentType="text/html; charset=utf-8"
  6.    pageEncoding="utf-8"%>
  7. <%@ page import="java.util.Random"%>
  8. <%!
  9. boolean isPrime(int x) {
  10.     int i = 2;
  11.     if(x <= 0)
  12.         return false;
  13.     if(x <= 2)
  14.         return true;
  15.     while((x % i) != 0)
  16.         i++;
  17.     return (i == x);
  18. }
  19.  
  20. int factorial(int x) {
  21.     int result = 1;
  22.     for(int i = 1; i <= x; i++)
  23.         result *= i;
  24.     return result;
  25. }
  26. %>
  27. <%
  28. Random rnd = new Random();
  29. int x = rnd.nextInt(100);
  30. int y = rnd.nextInt(12) + 1;
  31. %>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  33. <html>
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
  36. <title>First JSP</title>
  37. </head>
  38. <body>
  39. <h1>My first JSP file</h1>
  40. Your host name/ip: <%=request.getRemoteHost()%><br>
  41. Current time on the server: <%=new java.util.Date()%><br>
  42. The number drawn is: <%=x%> and it is <%=isPrime(x) ? "a" : "not a"%> prime number.<br>
  43. The factorial of <%=y%> is <%=factorial(y)%>.<br>
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement