File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes How to get data from HTML using JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to get data from HTML using JSP" Watch "How to get data from HTML using JSP" New topic

How to get data from HTML using JSP

Arpit Shrivastava

Joined: Jul 17, 2012
Posts: 5
hi All,

This is my first post in Javaranch, I need guidance from you all.
In my application we are using javascripts executeCommand method which helps to export data in csv format but this functionality is working with internet explorer only.
Now to run it with all browsers i am trying for new approach.
I am getting all data from java code and it's already loads in HTML means in my page now i want to export it to CSV.
Is there any way to parse html using jsp than right data into CSV.
As per mentioned approach i am thinking i'll get all data in HTMl so when some one click on export data link call will redirect to JSP and JSP can parse data from html and then export it to CSV.

I am not very much sure is it possible or not :(

Can some one please provide suggestion on it.

Note : We have filter on page so with each selection we are getting different values which need to be export on CSV.
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

Hi Arpit Java Ranch welcomes you.

You can use several Java script functions to run your code in all the browsers. Then you are asking about retrieving data from the Html through Jsp. This is quiet an older fashion ,you can get the value to jsp but what happens is the performance of your application will get reduced. Try using servlet to retrieve from Html so that your performance of application wont get affect
Arpit Shrivastava

Joined: Jul 17, 2012
Posts: 5
hi Venkat,

thanks for the reply.
Actually the problem is with Java script only .

I haver gone through with below forum :

and my problem is very similar, We are doing the same and getting data from java to jacascript but at the time of click to export its not opening.

and i am not able to export data in csv, So now i am trying to parse data from HTML using of seperate jsp and trying to write it on click.

Could you please suggest javascript method which will help us with same functionality like executeCommand.

Arpit Shrivastava

Joined: Jul 17, 2012
Posts: 5
hi ,

Yes i understand this forum is for JSP and my question was relevant to JSP only i have just tried to explain issue with members , With my new approach i am trying to Parse HTML using JSP because i have all relevant data in HTML.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Arpit Shrivastava wrote:my question was relevant to JSP

I don't see how it's relevant to JSP at all. As far as I can see it's about Javascript. At least according to you:

Actually the problem is with Java script only .

However there's a good chance that I don't understand what you are trying to ask. Can you provide a different explanation of what you want to do? In this explanation, tell us what you want to happen and where you want it to happen.
Arpit Shrivastava

Joined: Jul 17, 2012
Posts: 5
Hi can someone please help me with executeCommand replacement approach. I have shared relevant issue below with my post.
Arpit Shrivastava

Joined: Jul 17, 2012
Posts: 5
Hi Paul Clapham,

Yes you are right my problem was related to JS only but to fix this issue i am trying to get data from HTML using JSP.
I have implemented solution as well thanks to all for kind support.
Please find details below :

Question 1: What was the problem?
Ans: Problem was related to executeCommand function which is not working with any of the browsers except internet explorer 6.

Question 2: What was the approach to fix this issue?
ans : Earlier data is writing in CSV using executeCommand but it was only for internet explorer 6,I have fixed this issue with all of the browsers using JSP.
I have written one independent jsp and one new function in JS to call this JSP.Now i am able to get and write data in CSV with all browsers.
Please find JSP code below :


String csvFileContain = request.getParameter("csvData");
csvFileContain=csvFileContain.replaceAll("\"\"", "\",\"");
String disposition = "attachment; fileName=data.csv";
response.setHeader("Content-Disposition", disposition);
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Well, I don't understand what that code does, and you could hardly call it JSP; it's just Java code which is inserted into one of those old-fashioned scriptlets and would be better off in a servlet containing only that Java code. However if it does whatever you needed done, then I won't complain too much.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60774

And, one cannot "call" a JSP scriptlet from JavaScript.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dave MacLean
Ranch Hand

Joined: May 10, 2011
Posts: 49

The code takes an input parameter (csvData) as posted from the browser, and sends it back with an HTTP header (ContentType) such that the browser will receive it as a CSV file. If Arpit shared the URL for his JSP we could all call it from web pages to convert any CSV data to a CSV file via a browser. He didn't post the Javascript though that he used to call it/post to it.

Dave MacLean our book (Pro Android 4)
It is sorta covered in the JavaRanch Style Guide.
subject: How to get data from HTML using JSP
Similar Threads
Unit Testing the page validation errors
Session Data Vs Session Overhead
Export data to various formats in jsp using taglibs - how?
Microsoft Office SDK for java
<rich:dataScroller> is not rendering the data for export