Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSTL <c:out> and PageContext: need help!!!!!!!!!!!!!

843836Jun 2 2005
hi, i'm finding problems using core tag libraries, and i can't understand how to solve but expecially WHY i'm getting all those compilation errors....
first, i post my jsp's scriptlets section for evaluating errors, but please, firstly go to the end of scriptlet's section to understand what i'm asking.
################# JSP'S SCRIPTLETS SECTION ##############
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page session="true"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
   
<%@page import="services.sessionservice.*"%>
<%@page import="util.*"%>

<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<jsp:useBean id="loginManagement" class="bflows.LoginManagement" scope="session"/>
<jsp:setProperty name="loginManagement" property="nickName" param="nickName"/>
<jsp:setProperty name="loginManagement" property="password" param="password"/>
<jsp:setProperty name="loginManagement" property="loggedOn" value="false"/>
<%
    Cookie[] cookies = request.getCookies();
    String message = null;
    // SETTO UN ATTRIBUTO CON SCOPE PAGE PER L'UTILIZZO CON LE TAGLIBS PER L'OUTPUT IN XML
    // LO UTILIZZO COME SE FOSSE UNA VARIABILE PER POI EFFETTUARE IL GIUSTO OUTPUT.
    //
    // ######################## ENGLISH FOR JAVA.SUN FORUM #####################
    //
    // "OUTPUT" AND "MESSAGE" ARE ATTRIBUTES SETTED TO CHOOSE WHICH XML NODE I WANT TO SELECT
    // FOR OUPUT.
    pageContext.setAttribute("output","login");
    pageContext.setAttribute("message",null);
    String output = "login";
    String action = request.getParameter("action");
    
    // Controllo che (1� if) esista il cookie NICKNAME e che contenga dei valori; poi controllo che (2� if)
    // I valori contenuti corrispondano a quelli della sessione corrente.
    if(cookies != null) {
        if(Session.getValue(cookies,"NICKNAME",0) != null && Session.getValue(cookies,"NICKNAME",1) != null){
            if(Session.getValue(cookies,"NICKNAME",0).equals(loginManagement.getNickName()) 
            && Session.getValue(cookies,"NICKNAME",1).equals(loginManagement.getSessionID())) {
                loginManagement.setLoggedOn(true);
            }
        }
    }
    if(action != null){
        if(action.equals("login")){
            loginManagement.logon();
            if(loginManagement.getCookies() != null){
                for(int i=0;i<loginManagement.getCookies().length;i++){
                    response.addCookie(loginManagement.getCookies(i));
                    cookies=loginManagement.getCookies();                    
                }
                loginManagement.setLoggedOn(true);
            }
        }
        if(action.equals("logout")){
            loginManagement.setCookies(cookies);
            loginManagement.logout();
            // Rispedisce i cookie al client con MaxAge = 0, cos� questi verranno cancellati.
            for(int i=0;i<loginManagement.getCookies().length;i++){
                response.addCookie(loginManagement.getCookies(i));
            }
            loginManagement.setLoggedOn(false);
        }
    }
    if(loginManagement.getLoggedOn()){
        // MOSTRA IL MESSAGGIO DI BENVENUTO (SHOWS THE WELCOME MESSAGE)
        pageContext.setAttribute("output","welcome");
        output = "welcome";
    }
    else {
        if(action != null && action.equals("logout")){
            // TORNA ALL'INIZIO (SHOWS THE LOGIN FORM)
            pageContext.setAttribute("output","login");
            output = "login";
        }
        else {
            if(loginManagement.getResult() == -1){
                throw new Exception("Errore nell'applicazione: consultare i log");        
            }
            if(loginManagement.getResult() == -2){
                // STAMPA IL MESSAGGIO DI ERRORE (PRINTS THE ERROR MESSAGE)
                pageContext.setAttribute("message",loginManagement.getErrorCode());
            }
        }
    }
%>
############# END OF SCRIPTLETS' SECTION ###########

now i'll paste 2 short taglibs sections which will be appended after the code i pasted above: the first working, the second not compiling:

################## FIRST TAGLIB SECTION #############
<c:set var="xmlDocument" scope="page">
    <ROOT>
    <%if(output.equals("welcome")){%>
        <WELCOME>
            <NOME><%=loginManagement.getNome()%></NOME>
            <COGNOME><%=loginManagement.getCognome()%></COGNOME>
            <CREDITI><%=loginManagement.getCrediti()%></CREDITI>
        </WELCOME>
    <%}%>
    <%if(output.equals("login")){%>
        <LOGIN></LOGIN>
    <%}%>
    <%if(output.equals("error")){%>
        <ERROR><%=loginManagement.getErrorCode()%></ERROR>
    <%}%>
    </ROOT>
</c:set>

<x:parse xml="${xmlDocument}" var="xml"/>
<c:set var="xslUrl"><%="/XSL/Login.xsl"%></c:set>
<c:import var="xslDocument" url="${xslUrl}" scope="page"></c:import>
<x:parse var="xsl" xml="${xslDocument}"/>
<x:transform xml="${xml}" xslt="${xsl}"/>
###################### END #########################

################## SECOND TAGLIB SECTION ###########
    
<c:set var="xmlDocument" scope="page">
    <ROOT>
    <c:if test="${pageScope.output == 'welcome'}">
        <WELCOME>
            <NOME><c:out value="${loginManagement.nome}"></c:out></NOME>
            <COGNOME><c:out value="${loginManagement.cognome}"></c:out></COGNOME>
            <CREDITI><c:out value="${loginManagement.crediti}"></c:out></CREDITI>
        </WELCOME>
    </c:if>
    <c:if test="${pageScope.output == 'login'}">
        <LOGIN></LOGIN>
    </c:if>
    <c:if test="${pageScope.message != null }">
        <ERROR><c:out value="${loginManagement.errorCode}"></c:out></ERROR>
    </c:if>
    </ROOT>
</c:set>

<x:parse xml="${xmlDocument}" var="xml"/>
<c:set var="xslUrl"><%="/XSL/Login.xsl"%></c:set>
<c:import var="xslDocument" url="${xslUrl}" scope="page"></c:import>
<x:parse var="xsl" xml="${xslDocument}"/>
<x:transform xml="${xml}" xslt="${xsl}"/>
###################### END #########################

can u help me to understand why the second section doesn't works? if i'll be ogliged to use the first one, i won't be able to completely write code using taglibs, and so my code will be horrible! a mix of scriptlets syntax and taglibs' xml one.

Compiling jsp with netbeans 4.0 the error is:

Compiling 1 source file to /home/ghido/WebProjects/WebDocumentationXML/build/generated/classes
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:252: jspxmeth_c_if_0(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.SetTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_if_0(_jspx_th_c_set_0, jspxpage_context))
^
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:256: jspxmeth_c_if_1(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.SetTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_if_1(_jspx_th_c_set_0, jspxpage_context))
^
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:260: jspxmeth_c_if_2(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.SetTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_if_2(_jspx_th_c_set_0, jspxpage_context))
^
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:292: jspxmeth_c_out_0(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.IfTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_out_0(_jspx_th_c_if_0, jspxpage_context))
^
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:296: jspxmeth_c_out_1(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.IfTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_out_1(_jspx_th_c_if_0, jspxpage_context))
^
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:300: jspxmeth_c_out_2(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.IfTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_out_2(_jspx_th_c_if_0, jspxpage_context))
^
/home/ghido/WebProjects/WebDocumentationXML/build/generated/src/org/apache/jsp/Login_jsp.java:404: jspxmeth_c_out_3(javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.PageContext) in org.apache.jsp.Login_jsp cannot be applied to (org.apache.taglibs.standard.tag.el.core.IfTag,javax.servlet.jsp.PageContext)
if (_jspx_meth_c_out_3(_jspx_th_c_if_2, jspxpage_context))
^
7 errors

Can you help me??

And also, is the "pageContext.setAttribute()" method the correct way to select output as i did, or do u know a better one?

Thanks a lot, bye.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 30 2005
Added on Jun 2 2005
0 comments
284 views