Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!