Dúvida Stuts1 para fazer Botões

2 respostas
kaede

Bom dia a todos!
Estou usando o struts1 e encontrei o seguinte problema:
Preciso mudar a Action por meio dos botões, por ex:
Um botão(Submit) chama incluir.do
Outro botão chama exclur.do
Coloquei um JavaScript para resolver isto mas não funcionou
não sei como fazer pois preciso dos dois botões, ajuda serão
bem vindas…abaixo segue o código:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
  <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html:html >

<head><title>Sistema de Teste do Struts</title>

<!--*********************************-->
 <script>   
      function mudarAction() {   
         document.form.action = "/excluir.do";   
      }   
   </script>        
           
               

<!--********************************-->
</head>
 
<html:errors/>



<html:form   action="/cad.contato.do"   >

<table bgcolor="Gainsboro">
<tr>
<td>Codigo:</td>
<td><html:text maxlength="5"  size="6" property="contato.id"/> 
Tipo: <html:select   property="contato.tipo" >
<html:option value="1">MEMBROS</html:option>
<html:option value="2">VISITANTES</html:option>
<html:option value="3">SIMPATIZANTES</html:option>
</html:select></td>

<td></td>
</tr>

<tr>
<td>Nome:</td>
<td><html:text maxlength="100"  size="60" property="contato.nome"/></td>
<td></td>
</tr>

<tr>
<td>Email: </td>
<td><html:text maxlength="100" size="60"   property="contato.email"/></td>
<td></td>
</tr>
<tr>
<td>Endereço:</td>
<td><html:text maxlength="100" size="60"  property="contato.endereco"/></td>
<td></td>
</tr>

<tr>
<td>Bairro:</td>
<td><html:text maxlength="50" size="22"  property="contato.bairro"/>
Cidade:<html:text maxlength="50" size="25"  property="contato.endereco"/></td>
<td></td>
</tr>

<tr>
<td>Cep:</td>
<td><html:text maxlength="10" size="13"  property="contato.cep"/>
Fone:<html:text maxlength="17" size="13" property="contato.fone"/>
Cel:<html:text  maxlength="17" size="14" property="contato.cel"/></td>
<td></td>
</tr>

<tr>
<td>Dt Nasc:</td>
<td><html:text  maxlength="17" size="13" property="contato.dtnasc"/></td>
</tr>

<tr>
<td></td>
<td>
   <input type="submit" name="enviar" value="Enviar">   
   <input type="submit" name="Excluir" value="Imprimir" onClick="mudarAction()"> 
</td>
<td> </td>
</tr>

</table>
</html:form>


</html:html>

2 Respostas

rod

Document possui um array para todos os forms da pagina.
Caso exista apenas 1 formulario ou este seja o primeiro formulario da pagina, tente assim no seu javascript:

document.forms[0].action = "/excluir.do";
kaede

Muito obrigado, consegui resolver com sua ajuda DESEJO UM ÓTIMO DIA PRA VOCÊ.

Criado 30 de junho de 2009
Ultima resposta 30 de jun. de 2009
Respostas 2
Participantes 2