|
How to run Java code in a JSP page |
|
|
This Java tip illustrates an example of running Java code in a JSP page. Java code
fragments in a JSP page is called a scriptlet. This example demonstrates how to
include scriptlets in a JSP page. Use the out variable to add text to the generated
output.
<%
double rand = Math.random();
if (rand < .1) {
out.println("you win!");
} else {
out.println("try again");
}
%>
|
This example defines a method that can be used in a scriptlet in the page:
<%!
String getMsg() {
double rand = Math.random();
if (rand < .1) {
return "you win!";
} else {
return "try again";
}
}
%>
<%
// Use the method
out.println(getMsg());
%>
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.