Simple - use a servlet. JSP always assumes you want to write an HTML page.
Bill, I have tried to use servlet but I had difficulties in calling the bean.
FYI, I am using bean to store the value. By using jsp, I can call the bean using:
<jsp:useBean id="beanAnalysis" class="bean.Analysis" scope="application"/>
AFAIK, bean can only be called from servlet if the servlet is called by another servlet and not by jsp.
Do you have any information on how I can use servlet in this context?
//CALCULATE ENERGY PERFORMANCE
SolarGainCalculation sgc = new SolarGainCalculation();
response.getWriter().print(beanAnalysis.getCurrentEnergyPerformance()); //THIS IS THE VALUE I RETURN TO AJAX
posted 8 years ago
Bear Bibeault wrote:
Iman Paryudi wrote:I have a problem in returning response to AJAX from jsp.
I have tried this code:
You have Java code in a JSP? In 2012?
What's the value of result?
You haven't given us any details at all. What type of response are you trying to write? How are you formulating result? Where is this code embedded?
First of all, let me explain what I am trying to do.
I am trying to make a gui using dojo slider. What I want is that each time user slide the slider, the current value of the slider will be displayed in the textbox beside it.
Next, this value will be used in further calculation. The result of this calculation will be displayed in another textbox in the page.
What I have done is: I create AJAX code to send the current value of the slider to be calculated by java code. The value sent is of type float. I use jsp to write the java code for the calculation.
In the jsp page, I have to call bean because some data needed for the calculation are stored in this bean. This is my reason to use jsp and not servlet.
Acutally I am already able to send the value from this calculation back to AJAX. The problem is that the returned value is not only contained numeric value but also string (HTML tags) as I mentioned in my question.
Meanwhile I want the returned value only contain numeric value. This is important since the value will be used again in the next calculation.
I have tried a way to eliminate the string but no luck.
Below is my coding.
This is coding that contains AJAX
And below is the coding that return the value to AJAX: