cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to generate html-code using csv input with JSP or JAVA???

Former Member
0 Likes
542

Hello,

I want to read out a .csv-file and generate html-code dynmically with JSP in an EP6 Application. The problem is, that the csv-file can’t be located or openend.

BTW if every knows a good tutorial or weblog for this, please post the link.

It’s located in a par-archive under:

/>dist>files

I tried various methods, in the doContent mehtod or with JSP. Everytime same result.

Here part of the code I tried in the doContent():

public class CSV extends AbstractPortalComponent

{

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

String strWRoot = request.getWebResourcePath();

String contentCSV="", line="";

String linesep = System.getProperty("line.separator");

File fileLoadCSV = new File(strWRoot+"/files/ma_infosysteme.csv");

boolean exCSV = fileLoadCSV.exists();

boolean reCSV = fileLoadCSV.canRead();

int a=0;

if(exCSV&&reCSV){

response.write("ok");

try {

BufferedReader inputCSV = new BufferedReader(new FileReader(fileLoadCSV));

while((line=inputCSV.readLine())!=null){

contentCSV=contentCSVlinelinesep;

a++;

}

inputCSV.close();

}

catch(IOException ioex){

System.out.println("Fehler");

}

}

else {

response.write("not ok");

};

response.write("<br>Wroot: "+strWRoot);

response.write("<br>File: "+fileLoadCSV);

response.write("<br>exists: "+exCSV);

response.write("<br>read: "+reCSV);

response.write("<br>Input: "+contentCSV);

}

}

The Output is:

not ok

Wroot: /irj/portalapps/DHTML

File: \irj\portalapps\DHTML\files\ma_infosysteme.csv

exists: false

read: false

Input:

So thanks to everyone who can give me a good hint.

Bye.

Accepted Solutions (1)

Accepted Solutions (1)

0 Likes

Without really looking too much into this it looks like the problem is with the way in which you are trying to open the file. I believe that when creating a File object you need to use a physical path. By using the getWebResourcePath() method you are retrieving the URL to this file and not the physical path name. There is another method (can't remember the exact name) called getPublicResourcePath() (or something similar) which will return the physical path to this file, i.e. c:\usr\sap\.....etc. If you try it this way it may well work

I hope this helps

D

Answers (0)