Open CSV:
It is a very simple csv (comma-separated values) parser library for Java. It was developed because all of current csv parsers I've come across don't have commercial-friendly licenses.
Download Open CSV jar file from OpenCSV
Add jar to your portlet
Just write file tag in your jsp page
<aui:form action="<%=BulkImportURL.toString()%>" method="post" name="fm" enctype="multipart/form-data">
<aui:input name="QuestionAnswerAttach" id="QuestionAnswerAttach" type="file" label="Upload your Question Answer key"></aui:input>
<aui:button type="submit" value="Upload Questions"/>
</aui:form>
Then in your action class
Inside your method write
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
java.io.File document = uploadPortletRequest.getFile("QuestionAnswerAttach");
CSVReader readers = new CSVReader(new FileReader(document));
List<String[]> myEntries = readers.readAll();
for(int i=0;i<myEntries.size();i++){
String[] s = myEntries.get(i);
System.out.println(s[0]);
java.io.File document = uploadPortletRequest.getFile("QuestionAnswerAttach");
CSVReader readers = new CSVReader(new FileReader(document));
List<String[]> myEntries = readers.readAll();
for(int i=0;i<myEntries.size();i++){
String[] s = myEntries.get(i);
System.out.println(s[0]);
}
And you can store the value in database.
hello ma,am
ReplyDeletei have tried to implement this code but i am not apply to resolve the dependency.