Send list of objects as response in Java [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Is it possible to send a list of objects as a response to a HttpGet request in Java? I can't find anything about how to accomplish this.

Yes, it possible to send the list of objects as a response to GET/POST response.
It would entirely depend on how you are exchanging data between client and server. For example, you are exchanging data in JSON then you have to use libraries like Jackson which can convert your Java object to JSON, if you are using XML then same told true for it.
Read here for available options with JSON, also feel free to read this answer, however it talks more about traversing JSON.
Updates based on OP's comment
Approach always remains same, you will send response to client in some format, you will use HttpServletResponse method like set content type etc. where you will set the content type (XML or JSON etc.) and write to the response stream and then flush the stream.
Please have a look at this question.

Related

Making a request to end points wrong [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I submitted my project about fetching popular movies data in Udacity, and when i saw my review there was one thing to change, "The end points are perfectly implemented and fetches the correct result every time a request is made. But there is a small problem that instead of making a request to end point top_rated you are making a request to vote_average which makes it fetch wrong result!" But when i change to top_rated, the app doesn't fetch at all what is the problem? I don't get it, it fetches perfectly like this,And I don't see in the moviesDB nothing in JSON that says top_rated..
ScreeenShot
Information about the Project>> https://docs.google.com/document/d/1ZlN1fUsCSKuInLECcJkslIqvpKlP7jWL2TP9m6UiA6I/pub?embedded=true
My project >> https://drive.google.com/open?id=1wxYsxio2kbo44anndE9_93h13pWKTk0J
What does your json look like thats coming back from the url.
It looks like you also never make a request to
http://api.themoviedb.org/3/movie/popular?api_key=[YOUR_API_KEY]
based on your code and the project it seems like you need to fetch the top rated, then add it to your movie object.
in the project description look for Stage 1 - API Hints

How to exchange objects between client and server without using stub in rmi java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to send an object from client side to server side in order to modify its attributes and send it back from server to client - but without using a stub.
Any ideas?
Sure:
define your own protocol to enable remote calling
serialize the object on the one side into a stream of bytes, or more 2017ish: into a JSON string
send the bytes / string to the other side
deserialize, update; serialize and sent back.
That is a pretty generic answer; but given your extremely broad input; the best you can hope for (imho).
Further reading: on protocols, on serialization.
You don't need a stub class in the sense of generating one with rmic. Study the preamble to the Javadoc for UnicastRemoteObject for the conditions under which a dynamic stub is generated automatically.

Java: In socket programming if client write different type of Objects how server differentiate these object instances? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Well, my question is simple In socket programming if client write different type of Objects how server differentiate these object instances?
Updated:
Take for example if the client sends a string object how the server is suppose to know that it should cast the receiving bytes into a string object?
When you use a Socket you are using a TCP connection, so there's not any abstraction of the Application layer in this communication.
Remember TCP/IP stack:
++++++++++++++++++++++++++++
+ APPLICATION LAYER +
++++++++++++++++++++++++++++
+ TRASPORT (TCP/UDP) LAYER +
++++++++++++++++++++++++++++
The Socket only knows about TCP headers, so it doesn't know anything about the real type of the data, it only knows about TCP packets.
As Boris told you, the application layer is in charge of this know-how. You can use many options:
Send a header (an application header) that can tell every consumer how to deal with this data
Send a representation of the object. Use a technology-aware format: XML, JSON, YAML, etc...

how internally doPost method in servlet works [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Why query string is not getting created in doPost method of HttpServlet?
Is this reason is enough - it is supplying data in html body.
can anyone please clarify what actually happening
Get and post methods are almost the same, the only difference between these two methods is that: in post, query strings (name/value pairs) is sent in the HTTP message body of a POST request and in get, query strings (name/value pairs) is sent in the URL.
Why is this done this way, obviously, security reasons.
You do not want to see your login credentials in the url.

How to catch html response in Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm going to get Html responses and do some modifications on responses in Java before they reach client.
My idea is writing a servlet-filter but I don't know how to implement that.
What I got is :javax.servlet.ServletResponse resp and javax.servlet.ServletRequest req.
The essentials of filters
check the part on modifying responses
In your servlet filter, you can provide your own subclass of HttpServletResponseWrapper
After the call of chain.doFilter(...), your response wrapper will contain the html content, you'll be able to retrieve and transform it.
You can find a similar servlet filter there as example : http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html
use head first's chapter for filter there is an example of HttpServletResponseWrapper. very nice book for servlet and jsp s.

Categories