Yahoo! YSlow: A tool which analyzes web pages and suggests ways to improve their performance
Gzip: how to enable GZip compression in Tomcat
(Thanks to Leonardo A.)
Visualizzazione post con etichetta JSP. Mostra tutti i post
Visualizzazione post con etichetta JSP. Mostra tutti i post
martedì 13 ottobre 2009
giovedì 18 dicembre 2008
JSP: accedere al context da tagfile
Come accedere agli attributi passati al tagfile dal codice Java di una scriptlet? Accedendo al context tramite i metodi di SimpleTagSupport
Esempio:
<%@ attribute name="requiredPermissions" type="java.lang.String" required="true" %>
<%@tag import="it.___.security.AuthorizationException" %>
<%@tag import="it.___.web.beans.SessionBean" %>
<%
SessionBean sb = (SessionBean)session.getAttribute("sessionBean");
String requiredPermissions = (String)this.getJspContext().getAttribute("requiredPermissions");
if (sb.getEhealthSession().isDisabled(requiredPermissions))
{
throw new AuthorizationException("permission.check.permission.denied.header", new String[0]);
}
%>
venerdì 29 febbraio 2008
JSP: i tagfile
I tag file (v. http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html) sono una valida alternativa alla scrittura di un custom tag, consigliati nei casi più semplici e per riutilizzare il codice anche nelle pagine JSP.
1. Creare un file con estensione .tag nella cartella WEB-INF/tags (es: question.tag):
1. Creare un file con estensione .tag nella cartella WEB-INF/tags (es: question.tag):
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@ attribute name="question" type="it.aaa.bbb.Question" %>
<%@ attribute name="formName" type="java.lang.String" %>
<c:set var="questionId" value="${questionnaire.formId};${question.id.id}"
scope="request" />
<c:out value="${formName}"/>
<c:out value="${question.queTesto}"/>
<c:out value="${questionId}" />
2. Per usarlo, nelle pagine JSP:
<%@ taglib prefix="tag" tagdir="/WEB-INF/tags/" %>
<tag:question question="${question}" formName="questionnaireForm"/>
NOTA: per inserire il contenuto di un tag usare
<jsp:doBody/>
JSP: scriptlet nei tagfile
I tagfile non supportano la directiva page:
java.lang.RuntimeException: org.apache.jasper.JasperException ... page directive cannot be used in a tag file
Per esempio per importare le classi necessarie per gli scriptlet bisogna ricordare di usare invece la direttiva tag, invece:
<%@tag import="java.util.Random" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%
Random generator = new Random();
int randomIndex = generator.nextInt(4)+1;
%>
<c:set var="randomIndex" value="<%=randomIndex%>"/>
<html:img page="/images/back_header0${randomIndex}.jpg" />
Struts: passare parametri con html:link
<bean:define id="queueType" name="WorkFlowForm" property="queueType" />
<bean:define id="taskId" name="queues" property="taskId" />
<bean:define id="queueName" name="queues" property="queueName" />
<%
java.util.HashMap params = new java.util.HashMap();
params.put("queueName", queueName);
params.put("pageMode", queueType);
params.put("taskId", taskId);
pageContext.setAttribute("parameters", params);
%>
<html:link name="parameters" scope="page" page="<%=path%>">
Anchor
</html:link>
(v. TheServerSide.com)
Iscriviti a:
Post (Atom)