Cido_SB
Cido_SB

Reputation: 13

JSP history log from servlet

Some calculations are run via yy.java (let's consider as simple as it can be for the purpose of this question) and results get returned to xx.jsp (in a form x+y=z). I was wondering how can i have the whole history log showing on xx.jsp for all my previous calculations each time servlet is called. With example below, each time calculation is run old result gets deleted. I would like to have something like: 2+2=4 2*3=6 7-3=4....

.jsp (file)

The result is : ${result}

.java (file)

request.setAttribute("result", result);         
    request.getRequestDispatcher(".jsp").forward(request, response); 

Upvotes: 0

Views: 555

Answers (1)

Gray
Gray

Reputation: 116878

I would like to have something like: 2+2=4 2*3=6 7-3=4....

Are you talking about using logging in JSP files?

If you are talking about somehow building a result value, you could use a StringBuilder in your controller and build it along the way as you make calculations.

int result = 0;
StringBuilder sb = new StringBuilder();
// add something
results += x;
sb.append("added ").append(x).append(' ');
...
// multiply something
results *= y;
sb.append("multiplied ").append(y).append(' ');
// then add them to the model
request.setAttribute("result", result);         
request.setAttribute("resultLog", sb.toString());         

Upvotes: 1

Related Questions