top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

struts1 with Ajax using struts tags

+1 vote
867 views

I have a problem/doubt and describing here.I am using struts1.1(no plain jsp's only struts tags) and needs to implement ajax in that.Q-1) With out giving "action" property can't we write ?. If no I am using ajax in that
form(now my form having button to submit form data). Could any one please help how to add my response back to form variable in same page.

Login Success

my action class is

package app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class DetailsAction extends Action {    
 public ActionForward execute (ActionMapping mapping, ActionForm  form, HttpServletRequest request,HttpServletResponse  response) throws Exception    
 {
 RegisterForm detailsForm = (RegisterForm)form;
 detailsForm.setUsername("Struts");
 System.out.println("inr"+detailsForm.getUsername());
 return mapping.findForward("success");
 }    
} 
posted Nov 12, 2013 by Dewang Chaudhary

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

When you do AJAX in S1, you are always responding directly to the browser. You need to write your data to the ServletOutputStream and return null. You do not need to use any ActionForward.

answer Nov 12, 2013 by anonymous
Well, you *may* do that, but it's not a requirement; Ajax may return HTML etc.
Similar Questions
+1 vote

I have a web application which is deployed on a Tomcat server (version 7). I have set the session timeout value as 10 minutes in the web.xml file. In pages with no Ajax call, the session time out value is reset promptly. But it is not renewed on pages with Ajax calls. Web application is taking user back to Login screen even though some activity is happening on the page (with Ajax).

Can anyone help me?

0 votes

from the document,

Struts 2 support both DoJo plugin and JSON plugin,
which one is easy to plugin and use?
which one is more powerful?

+1 vote

I am creating an ajax call for a method which is protected by the TokenSessionStoreInterceptor. This means I need to pass the token onto the request.

I was expecting the s:token tag to accept data-foo="bar" attributes (they'd be passed along to the corresponding hidden elements), but this is not happening (I'd use this so I could retrieve the inputs with a
simple jquery select .find(":input[data-scope='save'], which retrieves me all the needed inputs as long as I mark them with that data-scope ).

My 2nd attempt was also unsuccessful - while doesn't break rendering, the class is not passed onto the hidden input elements.

Is there a reason for this? While in the case of data-foo this seems to be a missing feature, in the case of cssClass it's also misleading - you can set the property, but it doesn't have any consequence.

+1 vote

I am using struts 2.2.3 and doing client side validation using xml. I want to do validation for a field whose name is an ognl expression I have something like this :

Field is required

On debugging I can see It is adding field error properly. But i have a javascript which shows the field in red highlighted color and also shows messages that "fieldname is required". However fieldname is not coming in the message and it is not showing the required field in red highlighted color.

The same javascript code works fine for normal fields which have static name. Please can someone help in this, as I am new to struts ?

+2 votes

I can't see what's going on behind the scenes in this example so I'm asking for help in order to understand the Strtus process.

I run the example, leave empty "First Name" to make validation fail, and submit. Then go back to index:

http://localhost:8084/form_xml_validation

and click on edit. But "First name" is reset with the original value. It should be empty because Person instance is managed statically. In fact, other examples (preparable, exclude params) behave as expected, and return an empty String for the filed left empty.

The thing here is than I'm not understanding how Struts works here. I would appreciate if you help me with this.

Example is here:
http://struts.apache.org/release/2.3.x/docs/form-validation-using-xml.html

Code for checkout here:
http://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/

Examples doing as expected:
http://struts.apache.org/release/2.3.x/docs/exclude-parameters.html
http://struts.apache.org/release/2.3.x/docs/preparable-interface.html

...