3Website generation
The main purpose using cmsWorks is to create websites. Users login to the cmsWorks editors desktop and create documents storing the content. The generator service gets requests via URLs to read the contents from the CMSCore service and produce and return a website (in HTML or even any other format).
In a cmsWorks generator service JSPs are used to create the (website) content.
The behavior of JSPs
After sending a Request by passing an URL to the Generator in a browser the Generator service accepts the request (because it listens to the port), analyzes the URL and finds the JSP to execute. This JSP is compiled into a Servlet and will then be executed with the parameters Request and Response. The Servlet uses the Request to access the calling URL, parameters, request headers and attributes with information about the Generator service and the therefore requested CMS document. It produces the content, writing it into the Response and can add some response header information. The browser then is, finally, showing the created website.
The first request for a JSP compiles the Servlet. After this compilation, the Servlet ist loaded into the server as single instance. This Servlet then will serve every request handled by it. If the JSP file behind this Servlet is changed it will be recompiled and the old Servlet is replaced with the new one. So without restartarting any cmsWorks service, a simple change in the JSP file changes the website.
The content of JSP files
A JSP-File contains
- JSP configuration
- JSF includes
- JSP methods
- Inline java code
- Simple response output
<%@page import="java.util.HashMap, java.text.SimpleDateFormat"
session="false"
contentType="text/html;charset=UTF-8"
%>
<%!
private String translate(String s) {
return "interesting.";
}
%>
<!DOCTYPE html>
<html>
<head>
<title>TextFilterExample-1</title>
</head>
<body>
<%@include file="header.jsf"%>
<%
String s = "JSPs are " + translate("great!");
out.println(s);
%>
You called the URL <%= request.getRequestURI() %>
</body>
</html>Basic elements of a JSP
JSP configuration
<%@page import="java.util.HashMap, java.text.SimpleDateFormat"
session="false"
contentType="text/html;charset=UTF-8"
%>
The <%@page tag contains the configuration.
The property import contains all imports of classes used by this JSP. In the example above none of the classes is used but it's declared to show the syntax.
The property session is set false since the default is true and session management of the Generator service is not need most of the time.
The property contentType contains the value for the response header field Content-Type. Also the IDE Eclipse uses the information while developing the JSP.
JSP methods
<%!
private String translate(String s) {
return "interesting.";
}
%>
The tag <%! ... %> contains Methods and inner classes of the Servlet to be compiled.
Simple response output
The code <!DOCTYPE html>... is simple response output.
JSF includes
<%@include file="header.jsf"%>
The code <%@include file="header.jsf"%> includes the file header.jsf of the current directory into the JSP. The root folder for referencing JSPs, JSFs or any static files is the configured htdocs folder of the Generator service. The file content of header.jsf is "simply" copied into the JSP at the include position before compiling.
Inline Java code
<%
String s = "JSPs are " + translate("great!");
out.println(s);
%>
The code between <% and %> is inline Java code.
and also
<%= request.getRequestURI() %>
The code <%= value %> writes the Java value into the response output just like out.print() would do.
Within the Java code the properties out (Response-Outputstream), request (HttpRequest), response (HttpResponse) can be used since they are declared when the Servlet is compiled.
