• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to display Ajax result on the same jsp page

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been going through multiple examples on the web. They all say
1) go to one.jsp write the ajax code in the script tag and send the data from this jsp.
2) retrive the data and display in two.jsp

They are selecting the value from one jsp and displaying the value in the other jsp. What do I need to do if I need to select the value in one combo box, and display the related value on the second combo box of the same page.

I know no JSF
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prasad regula wrote:I know no JSF


So? What does JSF have to do with anything?

I have been going through multiple examples on the web. They all say
1) go to one.jsp write the ajax code in the script tag and send the data fr om this jsp.


First, some basic concepts. You are not really sending an Ajax request from a JSP. A JSP is merely a server-side template for creating HTML pages. So once the page arrives at the browser where JavaScript (and Ajax) can be executed, it's just an HTMl page. It is no longer a JSP. This may seem like a pedantic distinction, but's it's actually a very important concept to understand.

2) retrive the data and display in two.jsp


No. I'm sure that's not what they say. The whole point of Ajax is to make a request without having to go to another page.

Now, the Ajax request may use a JSP to format its own response. Maybe that's what you are confused about?

They are selecting the value from one jsp and displaying the value in the other jsp. What do I need to do if I need to select the value in one combo box, and display the related value on the second combo box of the same page.


"Same page" is always going to happen. You don't have a choice in the matter.
 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. It was helpful. I also found a good tutorial at http://www.learn-ajax-tutorial.com/. Even it speaks the same point you have said(Everything starts with a html).

I have one simple doubt. If this is a case what would be the situation if this page where I am applying the ajax, is not a starting page and comes somewhere in the middle of the page flow, and this page has some text to be displayed on the top say Name of the user. How do you manage the dynamic values with a html.
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I am not understanding your question. But it does sound more like an HTML question than a JSP question, so I've moved this post accordingly.
 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way you are right. It has become a html question from Ajax as ajax needs to be a html at the time of submitting the data to the webserver. My doubt here is as below:
1) has it not been a ajax issue,
I would have placed a jsp
Submitted the jsp to retrive the data from the database and
Redisplay the page with the retrived data from the database.

With JSP I have the facility of sending the HttpServletResponse data etc. Now if a html comes in between, how do we manage with the dynamic data sent by the server.
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prasad regula wrote:One way you are right.


One way?

Still not getting your question. Are you asking how to deal with the response once it's returned to the page? Or on the server?
 
prasad regula
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the server side in the servlet I have the following code



On the client side I need to display this user name on the top of the page. Had that been a jsp I would have written a following statements


Now this has become a html as I need to deal this page with ajax. How should I get that username attribute and display on the html.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're still missing Bear's point.

Both of the code samples you posted are run on the server side.
To see the code that will be interpreted on the client side, use your browser's "View Source" option.
You'll notice that there is no JSP code in there. You will only see the results from your JSP which, again, is interpreted on the server side.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

prasad regula wrote:One way you are right.


One way?


Hey, that's one more way to be right than *I* usually am.
 
reply
    Bookmark Topic Watch Topic
  • New Topic