Question

I am doing project in struts1 .In index.jsp file i am fetching records from the database and showing by using pagination.For pagination i used limit, offset and size as like suppose limit is 1000 offset and size are like (0,10) (10,10) (20,10) (30,10)..... For index page i created /page.java action class then i want to access these variables these class called limit,offset in the index page instead of storing session.Is there any way to access action class variables in the jsp file without storing in session.

Was it helpful?

Solution

You can access the varaibles used in action class from JSP page thro' two ways.

  1. Setting the values in Request Scope, as like this,

In Action method:

request.setAttribute("offset",offsetValue);
request.setAttribute("limit",limtValue);

In JSP page

${requestScope.offset}
${requestScope.limit}

2 . Using Form Object. Have a form object and set the values into it to retrieve in JSP page.(How ever the form obj would be in Request scope), Like this

public class PaginationForm {
    private int offset;
    private long limit;
    private int size;

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public long getLimit() {
        return limit;
    }

    public void setLimit(long limit) {
        this.limit = limit;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }
}

Set the values into the form and retrieve in JSP. You may keep this form as default form for the Action method or you can have this form Request.

OTHER TIPS

Create a form on the page. Set this values in the hidden fields on that form . Then you are able to get those in the Action class in form-bean.

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