Boa noite pessoal,
Estou desenvolvendo um ecommerce para projeto da faculdade, estou utilizando (pq é obrigatório) struts 1.
Estou com a seguinte dificuldade:
To tentando fazer um carrinho, para isso criei um Action que busca todos os meus produtos, essa Action será chamada através de um botão, no caso o botão PRODUTO. Quando o usuário clicar no botão produto, será direcionado para uma tela onde será listado todo os produtos.
Eu criei minha Action, mapeei no struts-config.xml, criei meus dois jsp’s tudo como eu aprendi a fazer porém, quando eu clico no botão PRODUTO, ele vai para uma tela onde fica tudo em branco.
Vou colocar meus códigos para que vocês possam me ajudar.
Action
public class PedidoAction extends org.apache.struts.action.Action {
private final static String SUCCESS = "pedido";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
List<Produto> lista = null;
ProdutoDao dao = new ProdutoDaoImpl();
try{
lista = dao.listaPedido();
}catch(Exception ex){
ex.printStackTrace();
}
session.setAttribute("pedido", lista);
return mapping.findForward(SUCCESS);
}
}
struts-config.xml
<action path="/venda" type="struts.action.PedidoAction">
<forward name="venda" path="/pedidoVenda.jsp"/>
</action>
1 JSP onde tem o botão
[code]<%–
Document : prod
Created on : 01/04/2010, 13:41:42
Author : Dani
–%>
<%@page contentType=“text/html” pageEncoding=“UTF-8”%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>
<link rel=“stylesheet” href=“prodIn.css” type=“text/css” charset=“utf-8” />
<link rel=“stylesheet” href=“tentar.css” type=“text/css” charset=“utf-8” />
<title>JSP Page</title>
</head>
<script>
function doSubmit(){
document.venda.submit();
}
</script>
<div id=“content”>
<form action=“venda.do” method=“post” name=“venda” id=“venda”>
<body bgcolor="#FFFFFF">
<center>
<table border=“0” cellspacing=“0” cellpadding=“0” class=“tablePosition”>
<tr>
<td colspan=“3”></td>
</tr>
<tr>
<td>
</td>
<table border=“0” align =“center” cellspacing=“0” cellpadding=“0”>
<tr>
<td align="Center">
<a ><font size="3" color="#FFFFFF">
<img /></font></a>
<!-- Aqui é onde ele está chamando -->
<a ><font color="#FFFFFF">
<img /></font></a>
<a ><font color="#FFFFFF">
<img /></font></a><br>
<label for="btnSalvar" title="Salvar">Meu Carrinho </label>
<label for="btnCancelar" title="Produto">Produto </label>
<label for="btnLimpar" title="Limpar">Deletar </label>
</td>
</tr>
</table>
<table border="0" align ="center" cellspacing="0" cellpadding="0">
</table>
</tr>
</table>
</center>
</body>
</form>
</div>
</html>
[/code]
JSP onde deveria sair o resultado
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.List,br.com.ecommerce.model.bean.Produto"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="h" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Resultado da Busca de Produtos</title>
</head>
<body>
<form
><font face="cambria">
<table border="0" align ="center" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4">
<img />
</td>
</tr>
<%!
List<Produto> lista;
%>
<%
lista = (List<Produto>)session.getAttribute("lista");
if(lista.isEmpty()) {
%>
<br><font color="FF0000">Nenhum produto encontrado!</font><br>
<%
} else {
%>
<table bgcolor=#E8E8E8" bordercolor="#009ACD" cellpadding="1" width="960px" border="4" align="center">
<tr>
<th>Cód. do Produto</th>
<th>Produto</th>
<th>Nome</th>
<th>Descricao</th>
<th>Valor Unitario</th>
<th>Valor Promocional</th>
<th>Quantidade</th>
</tr>
<%
for(Produto p: lista) {
%>
<tr>
<td align="center"><%=p.getId() %></td>
<td align="center"><img /></td>
<td align="center"><%=p.getNome() %></td>
<td align="center"><%=p.getDescricao() %></td>
<td align="center"><%=p.getValor() %></td>
<td align="center"><%=p.getValorPromocional() %></td>
<td align="center"><%=p.getQuantidade() %></td>
<td align="center">
<a >
<img ></a></td>
</tr>
<%
}
%>
</table>
<%
}
%>
<br>
<hr>
<a >Realizar outra busca</a><br><br>
</font>
</form>
</body>
</html>
Ao final, no browser aparece o seguinte endereço:
http://localhost:8084/Teste/venda.do
Alguem saberia me ajudar?
Desde já agradeço!