AEM Tutorial #37 | Servlet #2 | Resource Type Sling Servlet in aem
HTML-код
- Опубликовано: 15 сен 2024
- This tutorial explain about Resource Type sling servlet in aem. How to write resource type servlet using OSGi R7 annotations. I explain, how to use get and post methods in resource type servlet. How to use resource type servlet to submit form data. How to add methods, selectors and extensions to resource type servlet.
Demo code repo : github.com/aem...
your videos are so helpful. Thank you so much. please continue do so. it will help us a lot.
Thanks! saurabh singh
Best tutorial video you can find on sling servlets.
Thanks 🙏 utkarsh singh. Keep learning...
Awesome.... I like your clear explanation on each topics... keep going..
Thanks Vignesh Sekar
How did you pass those parameters from the UI form to the backend doPost method in the servlet?
SlingHttpServletRequest contains all form data in Post method. You could required data from this object. I explained this in many explained. Explore servlet related tutorials.
in my aem component there are extra fields dialog box in the component which i override from core components how should i remove those fields from my dialog box
Please show us servlet with ajax call. Also few tutorials on experience fragments n content fragments would be great.
Sure Mahesh Sah.
how i can view log like your screen at 16:37
why do we need selectors and extensions ?
Hi AemGeeks i tried to create the servlet with code at 5:25 in this video
I am getting below compilation error
package org.apache.sling.servlets.annotations does not exist
canot find symbol symbol: class SlingServletResourceTypes
i tried to add jar with quick fix but unable to resolve. Can you Please suggest?
You don't need any additional jar. You might using wrong annotation import. Please check if you are using correct import to use r7 annotation. Please check demo code available in git.
Hi . Not able to read my request payload from json body of my postman for a post method. Can u please help.
I did not understand your question completely. If you want to read json in service, you can use any api. Object Mapper you can use. Give me your exact problem statement, will try to answer.
I understand the process. I want send json file data to jcr by using post method, like upload any extension files at jcr. It means invoking aem author instance data. Can you please help me on this.
I did not understand your question completely, What I understood is, You want to upload a file and want save data of that file into jcr(file/node).
You can follow below solution, if your requirement is as above.
1. Create form with file field. Form I have already explained.
2. Read file in your code. This is plan java code. You can get from google/internet.
3. Now create a node of nt:file type where you want to store this file/data.
4. Add mixin to this node using addMixin method. add value 'mix:referenceable' .
5. Now add child node to this file node.
6. Add MIME type(node property) to node you created in step 5 to json. lets say you have json data.
7. Add data(node property) using jcr:data and value of this property should be, the data you read from original file.
Hi, I don't see the Registration component and content pages in Git Repo. Please could you commit the code
I guess, I have lost that code. Please try to rewrite.
Thanks for the video. I have one question Using R5 Annotation I can Register the same servlet using Path as well as Resource Type. Is that possible in R7. since we are using different annotations here
Yes you can!, Use both annotations in same servlet. I have explained this somewhere in next tutorials.
@@AEMGeeks Thank you for the quick response. i can take a look.
Also I'm unable to submit the values in "View as Published Mode"
Check for error in your error logs
Your tutorial s awesome ...can you please tell me use cases when we go for resourceTypes and when for paths
resourceTypes define for what resource this servlet will trigger.
Paths define for which path this servlet will trigger.
Please follow next tutorials, I did explain in detail.
@@AEMGeeks thank u so much
I really like your videos. Very informative and understandable. I have a small question. Request parameter is POJO class name right?
Thanks, Gayathri Malagondli, It is API provided call. Yes it is POJO like class. But I never check code.
I have one more question. After double-clicking the jar file to start the instance, it stuck at somepoint since so long. How can i fix it?
Not sure, We have to see logs to find issue. Ideally you should not start by double click. You can find issue when you need proper run mode. AEM will not start with required run mode. You have to update your quickstart file to add proper information. Please see this tutorial about how to install and set run modes.
ruclips.net/video/uLrSMMPDi8M/видео.html
I'm getting null values in servlet request parameters, if I submit form. But I can read response at path specified.. can you help here sir
What is error you are getting in logs. Is it CSRF token missing. check for this error. If you found this error, means CSFR token is not generating. You suppose to use a clientlib used to generate token.
Just check your logs
Can you please rewrite and committee the code for this tutorial
Code is already present in git
How we call resource type servlet using AJAX call?
As normal ajax call. you try in two ways.
1. AJAX call to servlet within AEM.
2. AJAX call to servlet from outside AEM.
3. Try both resourcetype and path type. You will understand many concepts. One concept, you will learn which is the favorite interview question 'Difference between resourcetype and path type servlet'
try once, You can get AJAX syntax from internet. this is not AEM specific.
@@AEMGeeks sorry bt u didn't understand my question. My question what will be value of Url field of ajax function, if we define the servlet using resource type
@@shaliniraghuvanshi7282 if you are calling from AEM than relative path is enough. If you are calling form outside AEM than complete path(including server ex. localhost:4502). Don't worry, I will give sample code.
Hi, can you turn on auto subtitles? Video so helpful, thanks)
I will enable.
Can you please post the registration.html file link?
I have doubt if I have this file. This file was create only for this tutorial. Let me see if I can find or rewrite this.