Running Java Code in a JSP Page - Java Servlet JSP

Java examples for Servlet JSP:JSP

Description

Running Java Code in a JSP Page

<%
    double rand = Math.random();
    if (rand < .1) {
        out.println("you win!");
    } else {
        out.println("try again");
    }
%>
<%!
    String getMsg() {
        double rand = Math.random();
        if (rand < .1) {
            return "you win!";
        } else {
            return "try again";
        }
    }
%>
<%
    // Use the method
    out.println(getMsg());
%>

Related Tutorials