Question

I want to return a line from the action method. My JSP is below

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
  <head>
    <sj:head/>
  </head>
  <body>
    <div id="div1">Div 1</div>
    <s:url id="ajaxTest" value="/test.action"/>

    <sj:a id="link1" href="%{ajaxTest}" targets="div1">
      Update Content
    </sj:a>
  </body>
</html>

The action:

@Action(value="test")
    public String jquery() throws IOException
    {
       System.out.println("hello");
        return SUCCESS;
    }

Currently, I am getting the output as success and I think it's due to the return SUCCESS. What I need is to popup some custom text sent from the test action. How can I achieve that?

Was it helpful?

Solution

Classically to return something from the action you need to put the result annotation on the action or method

@Result(location = "/pages/success.jsp") 

in the result you write the markup that will be inserted in the targets. You may need to supply http headers to turn off cache-control while the page is not reloaded.

Doing with the response you need your action to implement ServletResponseAware.

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