Content modified /path

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

19-06-2019

Hi All,

I have a contact form through which I'm submitting some data via ajax call to my servlet. i get a default page with content as follows on form submission:-

Content modified /fr/vous-avez-des-questions

Status

200

Message

OK

Location/fr/vous-avez-des-questions
Parent Location/fr
Path

/fr/vous-avez-des-questions

Refererhttp://localhost:4502/content/sample/contactform.html
ChangeLog

<pre>modified("/fr/vous-avez-des-questions/vous_etes");<br/>modified("/fr/vous-avez-des-questions/vous_etes_");<br/>modified("/fr/vous-avez-des-questions/choisissez_votre_profession_installateur");<br/>modified("/fr/vous-avez-des-questions/choisissez_votre_profession_prescripteur");<br/>modified("/fr/vous-avez-des-questions/choisissez_votre_profession_distributeur");<br/>modified("/fr/vous-avez-des-questions/nom");<br/>modified("/fr/vous-avez-des-questions/prenom");<br/>modified("/fr/vous-avez-des-questions/email");<br/>modified("/fr/vous-avez-des-questions/adresse");<br/>modified("/fr/vous-avez-des-questions/code_postal");<br/>modified("/fr/vous-avez-des-questions/ville");<br/>modified("/fr/vous-avez-des-questions/country");<br/>modified("/fr/vous-avez-des-questions/que_recherchez_vous_");<br/>modified("/fr/vous-avez-des-questions/type_de_produits");<br/>modified("/fr/vous-avez-des-questions/photos-produit");<br/>modified("/fr/vous-avez-des-questions/copie-de-facture");<br/>modified("/fr/vous-avez-des-questions/page_num");<br/>modified("/fr/vous-avez-des-questions/page_count");<br/>modified("/fr/vous-avez-des-questions/finished");<br/>modified("/fr/vous-avez-des-questions/form_build_id");<br/>modified("/fr/vous-avez-des-questions/form_id");<br/>modified("/fr/vous-avez-des-questions/captcha_sid");<br/>modified("/fr/vous-avez-des-questions/captcha_token");<br/>modified("/fr/vous-avez-des-questions/captcha_response");<br/>modified("/fr/vous-avez-des-questions/g-recaptcha-response");<br/>modified("/fr/vous-avez-des-questions/op");<br/></pre>

Go Back

Modified Resource

Parent of Modified Resource

Can someone let me know why this page is getting displayed?

Below is my servlet code

@Component(service = Servlet.class, property = { "sling.servlet.methods=POST",

"sling.servlet.paths=/bin/contactServlet" })

public class ContactServlet extends HttpServlet {

private static final long serialVersionUID = -6506682026701304964L;

Logger logger = LoggerFactory.getLogger(this.getClass());

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

VerifyRecaptcha recaptcha = new VerifyRecaptcha();

String gRecaptchaResponse = request.getParameter("g-recaptcha-response");

logger.info("Send post request gRecaptchaResponse: " + gRecaptchaResponse);

String formData = request.getParameter("form-data");

logger.info("formData response" + formData);

String flag = request.getParameter("flag");

logger.info("flag value" + flag);

if (flag.equalsIgnoreCase("contactus")) {

boolean verify = recaptcha.verify(gRecaptchaResponse);

logger.info("" + verify);

if(verify) {

//do something

}

}

}

Replies

Avatar

Avatar
Validate 50
Level 6
cquser1
Level 6

Likes

75 likes

Total Posts

313 posts

Correct reply

15 solutions
Top badges earned
Validate 50
Validate 25
Validate 10
Validate 1
Give Back 50
View profile

Avatar
Validate 50
Level 6
cquser1
Level 6

Likes

75 likes

Total Posts

313 posts

Correct reply

15 solutions
Top badges earned
Validate 50
Validate 25
Validate 10
Validate 1
Give Back 50
View profile
cquser1
Level 6

19-06-2019

Hi,

Few thoughts

1]Better to resolve servlet by resource type than via path "sling.servlet.paths=/bin/contactServlet"

2] Also, may be in call back function in the js, from where the servlet call is made, may be based on status [i.e, error/success] you might want to display a custom message.

However, am not sure why is the default page coming up.

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

19-06-2019

$.ajax({

url : '/bin/contactServlet',

type : 'POST',

dataType : 'json',

ContentType : 'application/json',

data : {

'g-recaptcha-response' : key,

'form-data' : demo,

'flag' : 'contactus',

},

success : function(data) {

console.log(data);

   //do something        

}

});

this is my ajax call.

1) can you let me know how to resolve servlet via resource path?
2)Please let me know if my success code is correct

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

19-06-2019

There is something wrong how you were calling post servlet because with your request default sling post servlet is being invoked which trying to create/modifying content.

Apache Sling :: Manipulating Content - The SlingPostServlet (servlets.post)