Expand my Community achievements bar.

Content modified /path

Avatar

Level 4

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

}

}

}

3 Replies

Avatar

Level 8

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

Level 4

$.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

Community Advisor

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)



Arun Patidar