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

140
Visualizações
Troubles with AJAX and Struts 1

I'm new with struts 1 and jQuery. I want to make a login using an AJAX request. This is my Jquery:

$.ajax({
            url : "login.do",
            type: "POST",
            dataType: "text",
            data:{
               //Got the values before

                "user" : user,
                "pass": pass
            },
            success: function(result){
                    if(result === "OK")
                        window.location = "hello.do";
            }
        });

My struts-config:

<action path="/login" type="com.arquitectos.struts.LoginAction" parameter="login">
            <forward name="OK" path="/"/>
        </action>

My LoginAction:

public class LoginAction extends MappingDispatchAction{
private final String error = "ERROR";
private final String success = "OK";
private final String session = "SESSION";
private Usuario user = new Usuario();

public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
    response.setContentType("text/texyt; charset = utf-8");
    response.setHeader("Cache-Control", "no-cache");
    try{
        String u = request.getParameter("user");
        String p = request.getParameter("pass");            
        if(u != null && p != null)
            if(!(u.equals("")) && !(p.equals(""))){
                user = TblLogin.Login(u, p);
                if(user!=null)
                    return mapping.findForward(success);
            }
    }catch(Exception ex){

    }
    finally{

    }
    return mapping.findForward(null);
}

The tbl file just execute the query and stuff... Now, my doubt is: how does the AJAX gets the "OK" from the forward? How to get that data and compare it in the jQuery.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I found the solution. It took me a while to figure it out. I was looking in the wrong place. I don't have to try to get data from the forwards.

A out.write("OK") is enough. That's the way my ajax request will get the answer.

about 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