Expand my Community achievements bar.

SOLVED

Posting data to POST.jsp

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Administrator

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

View solution in original post

6 Replies

Avatar

Level 10

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

Avatar

Level 2

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.

Avatar

Level 10

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. 

Avatar

Level 2

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. 

Avatar

Correct answer by
Administrator

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

Avatar

Level 10

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