Jstl

8 respostas
robinsonbsilva

Preciso de um help…
Estou usando JSTL e na hora de imprimir o conteúdo: “${cliente.endereco}” , ele parece não reconhecer,
ele imprime como texto “${cliente.endereco}” , sendo que tem contéudo nesse atributo.

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

<html>
	<body>
		<c:forEach var = "cliente" items = "${clientes}"> 
	  		<c:out value = "${cliente.endereco}" />
		</c:forEach> 
	</body>	
</html>

A servlet que passa a collection é essa:

package apresentacao;

import java.io.IOException;
import java.util.Collection;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import negocio.controle.ClienteController;

public class PesquisarClienteServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {

			String idCliente = request.getParameter("idCliente");
			ClienteController controller = new ClienteController();
			Collection clientes = controller.buscarCliente(Integer.parseInt(idCliente));
			
			request.setAttribute("clientes",clientes);
			request.getRequestDispatcher("/buscarcliente_resultado.jsp").forward(request,
	                response);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

8 Respostas

Fabricio_Cozer_Marti

A versão do JSP é 2.0?
A E.L está habilitada ? tanto no web.xml qto na sua .jsp …

Mauricio_Linhares

A declaração da taglib mais recente é essa aqui:

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

E você não precisa usar <c:out/>, basta colocar ${cliente.endereco} que ele vai mostrar (se o seu web.xml for 2.4).

robinsonbsilva

Desculpe pela minha ignorância, mas com faço para saber a versão do JSP, e do Web.xml(nele está assim:

<?xml version="1.0" encoding="ISO-8859-1" ?>"

seria isso??
Em relação a habilitar a EL eu acredito que esteja correto, eu fiz uns testes simples com <c: if> e rolou.

Agradeço desde já !

Mauricio_Linhares

Um web.xml 2.4 começa com essa declaração aí ó:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">	
  <servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>	
	
	<servlet>
		<servlet-name>Connector</servlet-name>
		<servlet-class>
			com.fredck.FCKeditor.connector.ConnectorServlet
		</servlet-class>
		<init-param>
			<param-name>baseDir</param-name>
			<param-value>/resources/</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>Connector</servlet-name>
		<url-pattern>/fckservlet.do</url-pattern>
	</servlet-mapping>
	
    <filter>
		<filter-name>filtroDoHibernate</filter-name>
		<filter-class>
			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
		</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>filtroDoHibernate</filter-name>
		<url-pattern>*.do</url-pattern>
	</filter-mapping>

	<listener>
		<listener-class>br.edu.cefetpb.spring.listener.PpqContextLoaderListener</listener-class>
	</listener>

</web-app>
robinsonbsilva

Se eu alterar apenas de :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>

    <display-name>::HIS::</display-name>

	<!-- Este filtro seta o encoding para cada request   
 	<filter>
	</filter> -->

	<!-- Adiciona o mapeamento do filtro "SetCharacterEncoding" 

    <filter-mapping>
    </filter-mapping> -->

	<taglib>
		<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
		<taglib-location>/WEB-INF/fmt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
		<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
		<taglib-location>/WEB-INF/c.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
		<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
		<taglib-location>/WEB-INF/sql.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
		<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
		<taglib-location>/WEB-INF/x.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
		<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
	</taglib>

    <servlet>
		<servlet-name>pqCliente</servlet-name>
        <servlet-class>apresentacao.PesquisarClienteServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
		<servlet-name>insEndereco</servlet-name>
        <servlet-class>apresentacao.InserirEnderecoServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
    </servlet>

	<servlet-mapping>
        <servlet-name>pqCliente</servlet-name>
        <url-pattern>/PesquisarClienteSrv</url-pattern>
    </servlet-mapping>
    
	<servlet-mapping>
        <servlet-name>insEndereco</servlet-name>
        <url-pattern>/InserirEnderecoSrv</url-pattern>
    </servlet-mapping>

	<session-config>
        <session-timeout>1800</session-timeout>
    </session-config>

	<mime-mapping>
	  <extension>xls</extension> 
	  <mime-type>application/vnd.ms-excel</mime-type> 
	</mime-mapping>
	
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list>
        
</web-app>

para:

<?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 	xmlns: xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
 	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>::HIS::</display-name>

	<!-- Este filtro seta o encoding para cada request   
 	<filter>
	</filter> -->

	<!-- Adiciona o mapeamento do filtro "SetCharacterEncoding" 

    <filter-mapping>
    </filter-mapping> -->

	<taglib>
		<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
		<taglib-location>/WEB-INF/fmt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
		<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
		<taglib-location>/WEB-INF/c.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
		<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
		<taglib-location>/WEB-INF/sql.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
		<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
		<taglib-location>/WEB-INF/x.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
		<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
	</taglib>

    <servlet>
		<servlet-name>pqCliente</servlet-name>
        <servlet-class>apresentacao.PesquisarClienteServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
		<servlet-name>insEndereco</servlet-name>
        <servlet-class>apresentacao.InserirEnderecoServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
    </servlet>

	<servlet-mapping>
        <servlet-name>pqCliente</servlet-name>
        <url-pattern>/PesquisarClienteSrv</url-pattern>
    </servlet-mapping>
    
	<servlet-mapping>
        <servlet-name>insEndereco</servlet-name>
        <url-pattern>/InserirEnderecoSrv</url-pattern>
    </servlet-mapping>

	<session-config>
        <session-timeout>1800</session-timeout>
    </session-config>

	<mime-mapping>
	  <extension>xls</extension> 
	  <mime-type>application/vnd.ms-excel</mime-type> 
	</mime-mapping>
	
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list>
        
</web-app>

Será que rola???

Mauricio_Linhares

O parser do fórum tá detonando o meu web.xml. o topo dele é assim ó:

Mauricio_Linhares

E retire as taglibs.

robinsonbsilva

Muito obrigado Mauricio,

Agora rolou, só que eu tive que manter a declaração das tag lib no web.xml…

Valeu!!!

Criado 24 de agosto de 2005
Ultima resposta 24 de ago. de 2005
Respostas 8
Participantes 3