Skip to content

Instantly share code, notes, and snippets.

@rurtubia
Created April 24, 2015 17:22
Show Gist options
  • Save rurtubia/a319ab4ae1beec2433c6 to your computer and use it in GitHub Desktop.
Save rurtubia/a319ab4ae1beec2433c6 to your computer and use it in GitHub Desktop.
Using JSP, runs simple java code on HTML. The browser just sees the HTML equivalent of the text. uses: * java for loop * HTML * JSP scriplets - Comment <%-- --%> - Declaration <% %> - Printing <%= %> * Adds no-cache snippet to avoid caching of code. Coded in Netbeans IDE 8.0.2 Run on Glassfish Server
<%--
Document : index
Created on : Apr 22, 2015, 12:58:57 PM
Author : rurtubiac
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%--Prevents from caching--%>
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<h1>Numbers from 1 to 10</h1>
<%--Initialization of a Java variable--%>
<%
int limit = 10;
%>
<%--Uses a java for loop--%>
<%--We can interrupt the java code with HTML by using the terminator scriptler--%>
<%
for (int i = 0; i < limit; i++) {
%>
<%--Use of the printing scriptlet--%>
<%= i+1%>
<br>
<%
}
%>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment