Question

Can I able to access method as action in Struts 2 with Codebehind plugin? Since there is no struts.xml file and its works as action!method in the URL.

Just I'm wondering to access a method

How to use Struts tag on class?

"@Action(name="action"), <s:url action="action" method="method" />

Class :

@Action(name = "JSONexample")
@Result(name="success",type=JSONResult.class,value="",params={"root","List"})
public class PartAction extends ActionSupport {

public String JSONexample{
-----
return SUCCESS;
}

public String readxml { }
}

if I access below method on submit button click , will I get the JSON data?

 $.getJSON('ajax/sayHi.action', formInput,function(data) 

So i can access action in URL as

localhost:7001/Sample/JSONmethod.action

to get the JSON data ?

Was it helpful?

Solution

As far as Codebehind Plugin doesn't support actions on methods you need to use Convention Plugin then use convention annotation @Action on method you want to be your action then you don't need ! explicit mapping.

If you continue to use the Codebehind Plugin, then you have to use Dynamic Action Invocation (DMI) to call the method other than mapped to your action.

Another time had to reread you question, it seems you want to access the action that has not mapping to the method other that execute:

  1. It isn't supported by the codebehind plugin;
  2. You have not mapped it via struts.xml. In this case the answer would be - no, you can't. But you can always use execute method!

If you continue with using of DMI better use s:url tag to construct the URL and use the method attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top