Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

328
Visualizações
How to stop my action from executing when I refresh my page?

Hello community I have the following problem, I am working on a project with JSP and Struts technology, I am really new because it is an old technology but it is what I had to work with.

I have the problem that calls are being made to the action when I refresh my page, I understand this is because in my URL is the last action that I send to call, so it is making a call back to that action, I have more than one form within my JSP which have different actions, I do not know if this is correct or have to change them to ajax or is there any way to solve it?

I have already added a POST method for the actions but it still has not worked.

My actions in configuration file:

<action name="plantillasAction_*" method="{1}" class="com.xxx.action.ActionPlantillas">           
        <result name="success">/jsp/plantillas/ResultTemplates.jsp</result>
        <result name="templateUpload">/jsp/plantillas/CreateCoordinates.jsp</result>
        <result name="saveCoordinates">/jsp/plantillas/SaveCoordinates.jsp</result>
        <result name="updateCoordinates">/jsp/plantillas/UpdateCoordinatesTemplate.jsp</result> 
        <interceptor-ref name="defaultSecurityStack">
            <param name="tokenSession.excludeMethods">init,templateFileUpload,processNavigator, 
                addCoordinateTemplate,deleteCoordinateToSave,saveTemplate,
                deleteTemplate,viewUpdateTemplate,addCoordinatesTemplateUpdate,
                searchTemplates,processUpdateNavigator</param>
        </interceptor-ref>
        <allowed-methods>
            templateFileUpload,
            processNavigator,
            addCoordinateTemplate,
            deleteCoordinateToSave,
            saveTemplate,
            deleteTemplate,
            viewUpdateTemplate,
            addCoordinatesTemplateUpdate,
            processUpdateNavigator,
            init, 
            searchTemplates
            
            
        </allowed-methods>
    </action>

My CreateCoordinates.jsp:

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-tags.tld" prefix="s" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html>
<html>
   <head>
      <meta name="decorator" content="contentLayout"/>
   </head>
   <body>
      <script src="${pageContext.request.contextPath}/html/js/jquery/alerts/jquery.alerts.js"  type="text/javascript"></script>
      <link rel="stylesheet" href="${pageContext.request.contextPath}/html/js/jquery/alerts/jquery.alerts.css">
      <script src="${pageContext.request.contextPath}/html/js/coordinatesTemplate.js" type="text/javascript"></script>
      <script src="${pageContext.request.contextPath}/html/js/templates.js"  type="text/javascript"></script>
      <script language="javascript">
         function update(value){
         var url="myAction?someVariable=value";
         window.open(url,"_blank","directories=no, status=no,width=1400, height=870,top=0,left=0");
         }
                    
         
         
         
      </script>
      <div id="content">
         <div class="wrap">
            <h1 style="margin-left:15px">
               <s:text name="label.module.template.header.update"/>
            </h1>
            <s:form action="plantillasAction_processUpdateNavigator" method="post" >
               <s:token />
               <hr style="border:15px;">
               <hr style="border:2px;">
               <div id="navigator" align="center">
                  <table align="center">
                     <tr>
                        <s:if test="currentPosition==imagePDFs.size() ">
                           <script type="text/javascript"> disableFirstButtons()</script>
                        </s:if>
                        <s:if test="currentPosition== 1 && imagePDFs.size()  != 1">
                           <script type="text/javascript"> enableFirstButtons()</script>
                        </s:if>
                        <s:if test="currentPosition==1 && imagePDFs.size()==1 ">
                           <script type="text/javascript"> enableAllButtons()</script>
                        </s:if>
                        <td>
                           <button id="firstPage" name="buttonAction" type="submit" value="3" ><<</button>
                        </td>
                        <td>
                           <button id="backPage" name="buttonAction" class="previous" type="submit" value="2" ><</button>
                        </td>
                        <td align="center">
                           <li>${currentPosition}/${imagePDFs.size()}</li>
                        </td>
                        <td align="right">
                           <button id="nextPage" name="buttonAction" class="next" type="submit" value="1">></button>
                        </td>
                        <td align="right">
                           <button id="endPage" name="buttonAction" type="submit" value="4">>></button>
                        </td>
                     </tr>
                  </table>
               </div>
               <div class="wrapper">
                  <div id="content">
                     <div id="pdf-container" >
                        <div id="signers-list">
                        </div>
                        <img id="pdf-page" src="data:image/png;base64,${image}" />
                     </div>
                     <!-- .\pdf-container -->
                  </div>
                  <!-- .\content -->
               </div>
               <!-- .\wrapper -->
               <div id="navigator" align="center">
                  <table align="center">
                     <tr>
                        <td align="center">
                           <button id="firstPage2" name="buttonAction" type="submit" value="3"><<</button>
                        </td>
                        <td align="center">
                           <button id="backPage2" name="buttonAction" class="previous" type="submit" value="2"><</button>
                        </td>
                        <td align="center">
                           <li>${currentPosition}/${imagePDFs.size()}</li>
                        </td>
                        <td align="rigth">
                           <button id="nextPage2" name="buttonAction" class="next" type="submit" value="1">></button>
                        </td>
                        <td align="rigth">
                           <button id="endPage2" name="buttonAction" type="submit" value="4">>></button>
                        </td>
                     </tr>
                  </table>
               </div>
            </s:form>
            <s:form action="routeAction_updateRoute" method="post" validate="false" namespace="/plantilla" theme="simple" onsubmit="return false;">
               <s:token />
               <table width="100%" cellspacing="0" cellpadding="0">
                  <tr height="10px">
                  </tr>
                  <tr height="40px" valign="middle" class="tablecells">
                     <td width="25%" class="negritas">
                        <s:text name ="label.module.template.info.plantilla" />
                     </td>
                  </tr>
                  <tr height="40px" valign="middle" class="tablecells">
                     <td width="14%">
                        <s:text name="label.module.template.add.nombre.plantilla"/>
                     </td>
                     <td>
                        <s:textfield id="idTemplateName" maxlength="80" size="40" 
                           value="%{currentTemplateView}" cssClass="inputbox"/>
                     </td>
                  </tr>
                  <tr height="5px">
                  </tr>
               </table>
               </table>
               <!-- TABLA CON BOTONES PARA BUSCAR INTEGRANTES A LA NUEVA RUTA (GRID)-->
               <table width="100%" cellspacing="0" cellpadding="0">
                  <tr height="40px" valign="middle" align="center" class="tablecells">
                     <td colspan="2" class="leftElement">
                        <button id="agregarFirma" class="action green" style="float:none" name="buttonActionCoordiante" type="submit" value="2">
                        <span id="fisnish" class="label" onClick='createDragDropElement()'>Agregar</span>
                        </button>
                        <button class="action green" style="float:none" id="btnCancelar" onClick="regresar('${pageContext.request.contextPath}')">
                           <span id="iniciar" class="label">
                              <s:text name="boton.cancelar"/>
                           </span>
                        </button>
                     </td>
                  </tr>
                  <tr height="15px">
                  </tr>
               </table>
            </s:form>
            
      </div>
      <script src="${pageContext.request.contextPath}/html/plugins/fontawesome/js/fontawesome-all.min.js" type="text/javascript"></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.943/pdf.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.10.11/interact.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.943/pdf.worker.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/utils/Draggable.min.js'></script>
      <script src="${pageContext.request.contextPath}/html/js/mainPdfUpdate.js" type="text/javascript"></script>
   </body>
</html>

When I enter my JSP this is the URL:

enter image description here

When I press any button of my first form it changes the URL to

enter image description here

If I refresh my page there, the action name is plantillasAction_processUpdateNavigator ,what I want in this case is to execute the action plantillasAction_viewUpdateTemplate.

My ActionPlantillas.java:

public class ActionPlantillas extends ActionSupport implements ServletRequestAware {

    private static Logger logger = LogManager.getLogger(ActionPlantillas.class);

    private HttpServletRequest request;
    
    public String viewUpdateTemplate() {

           //OPERATIONS
            return "updateCoordinates";
       
    }

    public String processUpdateNavigator() {
        //OPERATIONS
       return "updateCoordinates";
    }  




}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Create a SuccessAction with redirectAction class.

<action name="plantillasAction_*" method="{1}" class="com.xxx.action.ActionPlantillas"> 
<result name="success">/jsp/plantillas/ResultTemplates.jsp</result>
</action>
<action name="SuccessAction" class="SuccessPage">
<result name="success">/jsp/plantillas/success.jsp</result>
<action name="manual_order" class="materialTypeMasterAction" method="enquiry_process">
<result type="redirectAction">SuccessAction</result>
</action>

Like this: Prevent action resubmission

Please notice that if you do not change the URL, it will always resubmit the form. So if you implement this solution above, the url will change on success (redirectSuccess).

You don't have to really create a new success page, you can redirect to the original url/action in which the form is loaded (clean).

I hope this helps.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda