How can I do something or call back-end after upload a file





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.



Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.



    <portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>

<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>

<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>


Here is the ajax part



 function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}

$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});



function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);


}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}


Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?



I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.



if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());

}









share|improve this question

























  • how do you construct your urlForAjax?

    – Olaf Kock
    Feb 11 at 9:05











  • I'm not exactly sure what you are asking. However if you want to see an example of the front end side of a file upload in Liferay you can reference this gist.github.com/cmaggiulli/11b0d284e4e3f402907e179d1c261f31

    – Chris Maggiulli
    Apr 1 at 19:02


















0















I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.



Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.



    <portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>

<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>

<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>


Here is the ajax part



 function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}

$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});



function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);


}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}


Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?



I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.



if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());

}









share|improve this question

























  • how do you construct your urlForAjax?

    – Olaf Kock
    Feb 11 at 9:05











  • I'm not exactly sure what you are asking. However if you want to see an example of the front end side of a file upload in Liferay you can reference this gist.github.com/cmaggiulli/11b0d284e4e3f402907e179d1c261f31

    – Chris Maggiulli
    Apr 1 at 19:02














0












0








0








I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.



Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.



    <portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>

<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>

<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>


Here is the ajax part



 function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}

$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});



function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);


}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}


Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?



I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.



if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());

}









share|improve this question
















I'm trying to allow user upload their excel file, after that back-end will convert it as html format and suppose put it in the iframe src allow user preview in browser.



Now I'm trying to call the get path function for set the iframe src during page ready, but seems not work.



    <portlet:actionURL var="checkworkbook" name="checkWorkbook"></portlet:actionURL>
<b>Please Upload a Document</b>

<form name ="UploadExcelForm" action="<%=checkworkbook%>" method="post" enctype="multipart/form-data">
<input type="file" id="uploadedFile" name="uploadedFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
<button type="button" onclick="<portlet:namespace />uploadExcel()"> submit </button>
</form>

<div id="displayArea">
<iframe id="displayExcel" src="" weight=800 height=400>Please Upload a file</iframe>
</div>


Here is the ajax part



 function <portlet:namespace />uploadExcel() {
if ($('#uploadedFile').val() == null) {
alert("Please choose a file!");
return false;
}else{
document.UploadExcelForm.submit();
}
}

$(document).ready(function(){
<portlet:namespace />getDisplayPath();
});



function <portlet:namespace />getDisplayPath() {
var url = '<%=urlForAjax%>';
/*Make ajax call*/
$.ajax({
type : "POST",
url : url,
data: {
portletAction : "getDisplayPath"
},
success : function(data)
{
var obj = jQuery.parseJSON(data);
if(obj.jsonPath !=null){
var json = JSON.parse(obj.jsonPath);
$("#displayExcel").attr('src',obj.jsonPath);


}
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
/*Write you error-handling logic here*/
}
});
}


Moreover,I'm trying to use uploadExcel() part to make sure that user have select a file before upload, but it's not work, why?



I've do more testing, found that the problem maybe is getting the JSON, so I paste my back-end code here.



if ("getDisplayPath".equalsIgnoreCase(ajaxAction)){
String jsonPath = this.displayPath;
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("jsonPath", jsonPath);
response.getWriter().write(json.toString());

}






html ajax portlet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 2:33







summer hkg

















asked Jan 3 at 2:23









summer hkgsummer hkg

195




195













  • how do you construct your urlForAjax?

    – Olaf Kock
    Feb 11 at 9:05











  • I'm not exactly sure what you are asking. However if you want to see an example of the front end side of a file upload in Liferay you can reference this gist.github.com/cmaggiulli/11b0d284e4e3f402907e179d1c261f31

    – Chris Maggiulli
    Apr 1 at 19:02



















  • how do you construct your urlForAjax?

    – Olaf Kock
    Feb 11 at 9:05











  • I'm not exactly sure what you are asking. However if you want to see an example of the front end side of a file upload in Liferay you can reference this gist.github.com/cmaggiulli/11b0d284e4e3f402907e179d1c261f31

    – Chris Maggiulli
    Apr 1 at 19:02

















how do you construct your urlForAjax?

– Olaf Kock
Feb 11 at 9:05





how do you construct your urlForAjax?

– Olaf Kock
Feb 11 at 9:05













I'm not exactly sure what you are asking. However if you want to see an example of the front end side of a file upload in Liferay you can reference this gist.github.com/cmaggiulli/11b0d284e4e3f402907e179d1c261f31

– Chris Maggiulli
Apr 1 at 19:02





I'm not exactly sure what you are asking. However if you want to see an example of the front end side of a file upload in Liferay you can reference this gist.github.com/cmaggiulli/11b0d284e4e3f402907e179d1c261f31

– Chris Maggiulli
Apr 1 at 19:02












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015562%2fhow-can-i-do-something-or-call-back-end-after-upload-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015562%2fhow-can-i-do-something-or-call-back-end-after-upload-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith