[JSTL] Passar parar parâmetro para método que retorna String

3 respostas
P

Pessoal,

estou com a seguinte dúvida:

tenho um método que retorna uma String através de dois parâmetros passados, porem preciso utiliza-lo em uma JSP utilizando JSTL,
minha dúvida é a seguinte. Estou batendo cabeça para passar um parâmetro para esse método que deve retornar uma String em minha JSP.

Método da CLASSE StoreCommons

// Recupera atributo descritivo a partir de um CATENTRY_ID e nome do Atributo
	public String getDescriptiveAttributes(String argCatEntryId, String attr) {
		String attrDesc = "";
		try {
			ResultSet rs = getResultSet("SELECT "
					+ "ATTRVALUE.STRINGVALUE AS attr " + "FROM "
					+ "ATTRIBUTE INNER JOIN ATTRVALUE "
					+ "ON ATTRIBUTE.ATTRIBUTE_ID = ATTRVALUE.ATTRVALUE_ID "
					+ "WHERE " + "ATTRIBUTE.CATENTRY_ID = '" + argCatEntryId
					+ "' " + "AND " + "ATTRIBUTE.NAME = '" + attr + "' ");
			if (rs.next()) {
				try {
					attrDesc = rs.getString("attr").toString();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return attrDesc.toString();
	}

JSP

// Aqui recupero o id que é carregado com a página e passado como parametro no metodo [b]getDescriptiveAttributes[/b]
<c:set var="id" value="${catEntryIdentifier}"></c:set> 

<%
StoreCommons store = new StoreCommons();
String catEntry = request.getParameter("id");
%>

<p class="Autor">							
<%=strcm.getDescriptiveAttributes(catEntry,"professor")%>  //devo fazer essa chamada usando JSTL e retornar uma String
</p>
<small>
<%=strcm.getDescriptiveAttributes(catEntry,"qtdItens")%>  //devo fazer essa outra chamada usando JSTL e retornar uma String
</small>

Não estou conseguindo ter uma luz,
Qualquer ajuda é bem vinda.

Desde já Obrigado

3 Respostas

L

porto0503:
Pessoal,

estou com a seguinte dúvida:

tenho um método que retorna uma String através de dois parâmetros passados, porem preciso utiliza-lo em uma JSP utilizando JSTL,
minha dúvida é a seguinte. Estou batendo cabeça para passar um parâmetro para esse método que deve retornar uma String em minha JSP.

Método da CLASSE StoreCommons

// Recupera atributo descritivo a partir de um CATENTRY_ID e nome do Atributo
	public String getDescriptiveAttributes(String argCatEntryId, String attr) {
		String attrDesc = "";
		try {
			ResultSet rs = getResultSet("SELECT "
					+ "ATTRVALUE.STRINGVALUE AS attr " + "FROM "
					+ "ATTRIBUTE INNER JOIN ATTRVALUE "
					+ "ON ATTRIBUTE.ATTRIBUTE_ID = ATTRVALUE.ATTRVALUE_ID "
					+ "WHERE " + "ATTRIBUTE.CATENTRY_ID = '" + argCatEntryId
					+ "' " + "AND " + "ATTRIBUTE.NAME = '" + attr + "' ");
			if (rs.next()) {
				try {
					attrDesc = rs.getString("attr").toString();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return attrDesc.toString();
	}

JSP

// Aqui recupero o id que é carregado com a página e passado como parametro no metodo [b]getDescriptiveAttributes[/b]
<c:set var="id" value="${catEntryIdentifier}"></c:set> 

<%
StoreCommons store = new StoreCommons();
String catEntry = request.getParameter("id");
%>

<p class="Autor">							
<%=strcm.getDescriptiveAttributes(catEntry,"professor")%>  //devo fazer essa chamada usando JSTL e retornar uma String
</p>
<small>
<%=strcm.getDescriptiveAttributes(catEntry,"qtdItens")%>  //devo fazer essa outra chamada usando JSTL e retornar uma String
</small>

Não estou conseguindo ter uma luz,
Qualquer ajuda é bem vinda.

Desde já Obrigado

Onde foi criada a variavel “strcm” que você usa aqui? “strcm.getDescriptiveAttributes”

Se você só vai utilizar este método na JSP, crie ele como static e chame-o direto pelo nome da classe.

E

bicho

request.setAttribute(“nomeQualquer”,seuObjeto);//isso deveria ficar no seu servlet mais coloque onde quiser

e pra pegar por ‘EL’ na jsp

${nomeQualquer.seuAtributo}

ou

jstl

<c:out value="${nomeQualquer.seuAtributo}" />

E

vi agora

<c:set var=“id” value="${catEntryIdentifier}"></c:set>

<c:out value="${id}" />

ou

<c:out value="${catEntryIdentifier}" />

ou

só ${catEntryIdentifier}

cara isso é só tentar, se esforce um pouco

Criado 22 de julho de 2013
Ultima resposta 23 de jul. de 2013
Respostas 3
Participantes 3