Skip to main content
Level 2
Jul 28, 2016 6:05 PM UTC
Solved

Posting data to POST.jsp

Hi Team,

I am trying to post table data from my form to the POST.jsp using the following approach.

$.ajax({
                type: 'POST',
                url: '/url to the component's node/Organization.POST.jsp',
                data: {
                    'orgName': orgName,
                    'orgPhNum': orgPhNum,
                    'orgProgram': orgProgram,
                    'orgAddress': orgAddress,
                    'orgCity': orgCity,
                    'orgState': orgState,
                    'orgZipCode': orgZipCode,
                    'datePicker': datePicker,
                    'problemReproducible': problemReproducible,
                    'locations': locationArr,
                    'people': peopleArr,
                    'fileDetails': fileArr
                },
                success: function(data) {
                    //alert(data);
                },
                failure: function(data) {
                    //alert("failed");
                }
            });
        }); 

 I was able to get all the data in Servlet for a different case following the same approach .Not sure what path to give to make it work for POST.jsp as well

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
kautuk_sahni
kautuk_sahniAccepted solution
Level 9
Aug 1, 2016 12:10 PM UTC

Hi 

There is one more Helpx Article that is uploading an image. Here also we are posting image stream via POST method, and at the OSGI level (servlet) we are catering it with doPost ();

Link:- https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

// Here we are sending FormData Via Ajex call which is having POST as a Method.

    $.ajax({
    type: 'POST', 
    url:'/bin/updamfile',
    processData: false, 
    contentType: false, 
    data:formData,
    success: function(msg){
        alert(msg); //display the data returned by the servlet
}
});

 

Please have a look at this one, i hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni

6 replies

smacdonald2008
Level 10
Jul 28, 2016 6:27 PM UTC

Posting data to a post.POST.jsp is typically from an Adoptive form. See: 

https://helpx.adobe.com/experience-manager/using/posting-aem-6-form-data.html

If you are using AJAX outside of an adaptive form (ie - a JSP) - consider posting to an AEM Sling Java Servlet. 

See: 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Translate
Level 2
Jul 28, 2016 7:05 PM UTC

Was able to post form(Non adaptive one) details to servlet.

It had issues then accessing the Datasource Connection defined in the osgi configurations.

That is the reason I tried using POST.jsp approach.

Translate
smacdonald2008
Level 10
Jul 28, 2016 7:49 PM UTC

If you want to store data into a relational database from a servlet - use a DataSourcePool. This is the best practice. See this AEM community article that shows how to perform this use case: 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets1.html

This shows you How To get a DataSourcePool into a Sling Servlet. This way you can post to Servlet and then use DataSourcePool to get the data into a database. 

Translate
Level 2
Jul 31, 2016 4:54 AM UTC

Thanks for your response.

I tried using the shared article and ended up getting "No suitable driver found error".

I have the Oracle driver jar installed as bundle and I am able to connect to database using Data connection pool when using POST.jsp upon HTML form submission in AEM. 

Translate
kautuk_sahni
kautuk_sahniAccepted solution
Level 9
Aug 1, 2016 12:10 PM UTC

Hi 

There is one more Helpx Article that is uploading an image. Here also we are posting image stream via POST method, and at the OSGI level (servlet) we are catering it with doPost ();

Link:- https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

// Here we are sending FormData Via Ajex call which is having POST as a Method.

    $.ajax({
    type: 'POST', 
    url:'/bin/updamfile',
    processData: false, 
    contentType: false, 
    data:formData,
    success: function(msg){
        alert(msg); //display the data returned by the servlet
}
});

 

Please have a look at this one, i hope this would help you.

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
smacdonald2008
Level 10
Aug 25, 2016 11:05 AM UTC

Make sure you have the JSP files you are posting to in the correct location. See this example whick works:  https://helpx.adobe.com/experience-manager/using/querying-experience-manager-sling.html

Translate