• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Struts and AJAX together causing redirection problems.

 
Greenhorn
Posts: 1
IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am developing a web app using struts 1 and ajax together. However i am having some redirection issues.
I m pasting my code below :
struts-config.xml
<action
path="/login"
name="loginForm"
type="action.LoginAction"
parameter="method"
scope="request"
input="/login.jsp"
validate="false">
<forward name="success" path="/pages/my_home_page.jsp"/>
<forward name="failure" redirect="true" path="/pages/login.jsp"/>
</action>

and my login.js ( javascript file) ... this is where all my ajax code is present


$(function(){
//jAlert("hi");
$('#login_ok').click(function(){

$.ajax({
data:{username:$("#username").val(),
password:$("#password").val()},
type:"post",
url:"/Tourini/login.do",
success: function(response) { // on success..

},
failure: function(response){
jAlert("Error");
}
});

Action class :
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

System.out.println("Inside function LoginAction:loginUser");
ActionForward af = null;
try{

DynaActionForm dform = (DynaActionForm)form;
Users users = new Users();
String username = ((String)dform.get("username")).trim();
String password = ((String)dform.get("password")).trim();

System.out.println("username "+username+" and password "+password);

users.setUsername(username);
users.setPassword(password);

LoginService ls = new LoginService();
String result = ls.loginUser(users);
System.out.println("result is "+result);
if(result.equals("success")){
af = mapping.findForward("success");
}else if(result.equals("fail")){
System.out.println("failure to login");
request.getSession().setAttribute("invalidUser", "true");
af = mapping.findForward("failure");
}
}catch(Exception e){

e.printStackTrace();
}

return af;
}

on successful login, it should be redirected to my_home_page.jsp but it comes on the login.jsp page itself.

Please suggest some hint.. i m not able to get this.
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do you get in your console?
 
reply
    Bookmark Topic Watch Topic
  • New Topic