0

First of all: sorry for my bad grammer. English isn't my native language, but i will try to exlpain my problem as simple as i can.

I'm working on a web-application, where user can enter a link. (Question 1) This link should be send to the server/servlet and will be progressed to other things. (Question 2) After the progression, the servlet will send a json-array (?) back to the javascript-part of my app.

I'm completly new to this kind of stuff, but its very important to me, to find out how this works or better, how i can make this work. Its actually very simple, but i used plenty of weeks and cant figure it out.

The application is using the SAP UI5-libs (Question 3), where i would also like to know, if there is any possible way, to parse JSON with the UI5 libs.

I hope, i could explain my problem good enough, so i can get some help. Thanks to all!

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
luckyone90
  • 11
  • 2
  • consider splitting your questions up as question 3 in this case is woefully off-topic in the context of question 1 & 2. People who know the answer to question 1 & 2, also the subject of this post, won't necessarily know the answer to question 3. – Gimby Aug 18 '14 at 16:13
  • Sorry, but maybe there is someone who is using the SAPUI5 in this context and could help - was at least my thought, when i wrote the Questions. I will think of it next time. – luckyone90 Aug 18 '14 at 18:07
  • consider taking the tour to learn how SO and especially asking questions works: http://stackoverflow.com/tour – Gimby Aug 19 '14 at 07:02

1 Answers1

0

The 'sending' of the string to the server/servlet would happen via ajax in either POST or GET form. That is up to you.

I recommend you use a javascript plugin like jQuery (JQuery Ajax API) because the regular ajax code is a bit messy.

As for the servlet/server communicating back to the client is as simple as writing to the page. In a typical servlet context it would be something like

out.print("This is a message");

where Ajax automatically returns the content of the entire page upon callback.

So in conclusion: Consider test.jsp your servlet. I wish to send "Hi" from the client (being the browser) via GET to the servlet and I want the servlet to say "Hello" back.

I would open an ajax request of type GET to the url "test.jsp?param=Hi". In the servlet I receive this page request and process it. The servlet discards the parameter because it is not used and outputs "Hello" to the page.

In the client the ajax will have returned "Hello" and I can use this to put it into a var or whatever and all of this happened while not refreshing and not navigating in the original document where I did the javascript.

Another way is using websockets where you basically use sockets in javascript to send and receive any kind of data.

Also please check out this possible duplicate question: How to send a string to a servlet from javascript using xmlhttprequest

Community
  • 1
  • 1
Limnic
  • 1,826
  • 1
  • 20
  • 45