Passing image to controller class in JSON format in spring mvc - javascript

Is it possible to store an image and some column fields in mysql database using only AJAX without action attribute in form tag? I am using contentType as JSON in AJAX to pass my column fields.
Is there any solution to send the image in the JSON format. Kindly provide the solution.

Related

Form.io get JSON Data Component without submission?

In Form.io, I have the Data Component and this in the name of the input box write data[FirstName]. This is very hard to manage in a self programmed endpoint to save data on own server.
Is there is a way to get Data Component in JSON format for submit then in a ajax request?
Thanks in advance.

how to upload canvas image using struts2 [duplicate]

I need to retrieve rows in database with a image saved in byte array. How do I display the image using Strut2?
I have displayed it by using custom result. I passed the id and make an action search for it in the database. My problem is how to invoke this several times? I have an action that retrieve all the rows. How to call display image action from the list action? Or is there a better way to achieve this?
JAVA
My action has an list of the objects I want to show on JSP.
JSP
First way: I use iterator tag and on each iteration I want to display the image which is in byte array. I want call the action to retrieve the image here.
Second way: I tried this post and it is not working for me.
<img src="data:image/jpg;base64, <s:property value="imageData"></s:property> />" >
Image data is the image in string.
To retrieve rows in database there's many ways but all of them utilize JDBC API. You can map the object as an image array containing bytes or blob or clob data that you persist in the database.
Displaying the images required to send it to the browser. In the Struts2 there's a stream result type that could be used to output the image data to the browser.
Or use the Servlet API to transmit the data on the JSP similar like in How to send and display image from action class to JSP in Struts 2 answer.
Combining the experience from the answers that you already enlighten in the question to stringify data you may achieve suitable results.

Populating form components from database using innerHTML

I need to populate form components(either select,checkbox) from database. The fields of the form depend on each other, i.e I need to populate a component based on user selection on the previous component. To do that, I am using onchange method, from which I raise a AJAX request for the data that need to populate the next tag. Right now, I am returning the string(HTML data) from the controller in backend and setting the corresponding id's innerHTML to these string. I am curious, whether the approach is correct way or should I take the json as the output from AJAX call and generate the HTML in js and then set the innerHTML value to the corresponding id. I am using JSP as View.
i think building the json and building up the components in the page side is safer becuse it makes your business login separate from the view. If it is required to construct a dynamic table without a POJO then there is no other go you have to use the html string data as the output of ajax

How to send a date as JSON string to symfony2?

I try to send data from a HTML form to a REST API which is created with the Symfony 2 PHP framework. The form data is processed with javascript (AngularJS) and send as JSON string to the API. Sending the data as HTTP PUT request works well. The problem appears if I try to validate the data.
To validate the data I created a form class and use the form validation mechanism of symfony2. Here the problem appears. The validation mechanism does not recognize my date format ... I tried it with the following format :
{'year':'2014','month':'05','day':'15'}
and
2014-05-15
In both cases the validation throws the error "birthday:\n ERROR: This value is not valid.\n"
I would be very pleased if someone could give me a hint to solve this.
Thanks in advance

How to create a JQuery or Javascript Array from HTML Formatted HTTP Response?

I'm using a service called TrueFX that provides currency information based on HTTP request/response. I need to send the initial request to the base URL with username, and other parameters. The service responds with a session ID. A subsequent HTTP request is sent with the session ID and the instructions for output type (CSV or HTML). The second response provides an HTML table with the requested data.
The final destination for this data will be a chart via the JQPlot plugin for JQuery. JQPlot will accept an array instead of individual values to be plotted.
Questions:
Is it best to create the array of data using JQuery, plain ole Javascript or PHP?
Depending on response to above, how do I define the request to TrueFX, the TrueFX response containing currency data in HTML format? Is this just done through the $.ajax JQuery method?
How do I create and save the array for reference and use in my call to JQPlot?
Thanks so much for your advice, help and guidance.
First off I would recommend you work with the CSV format as it will be much easier to parse into an array of arrays for use in your chart (also data size will be much smaller). There are multiple CSV plugins for jquery that make this parsing pretty easy. Here is one I found real quick: CSV Plugin
You can use jquery's $.ajax to get the data from the remote service (using JSONP) and the CSV plugin to parse the returned data. Then you feed the resulting array of arrays into your chart.

Categories

Resources