Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Redirect a Form to the same page from Servlet after submission

Veena_Vikram
Community Advisor
Community Advisor

Hi

 

   I was just analyzing normal form handling from CQ(without using CQ form) and I got stuck in between.  I have a form which I am submitting to a servlet through POST. After processing i want the form to redirect to the same jsp. I am not able to figure out how to achieve this. Any help would be appreciated

 

Thanks

 

Veena

1 Accepted Solution
Ojjis
Correct answer by
Level 7
Level 7

Hi, there are probably a few ways of doing this. Here's two:

1) response.sendRedirect(req.getHeader("referer"));
This makes use of the referer header which may or may not be there, so it's not reliable all the time. 


2) Have the form pass the page it's on as an variable  and then use that for redirecting.
This of course could be a security risk so you need to check that the url submitted from the form to your servlet actually is residing on your page 🙂

Good Luck
/johan

View solution in original post

0 Replies
smacdonald2008
Level 10
Level 10

You want to submit data to a CQ Sling Servet, process the data using the Sling Servlet (ie - encode it), and then return the data back to the JSP. We have several community articles on how to do this.

See:

http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html

This walks your though how to do this. As an example of processing the data -- the data is encoded as JSON using the servlet. 

Ojjis
Correct answer by
Level 7
Level 7

Hi, there are probably a few ways of doing this. Here's two:

1) response.sendRedirect(req.getHeader("referer"));
This makes use of the referer header which may or may not be there, so it's not reliable all the time. 


2) Have the form pass the page it's on as an variable  and then use that for redirecting.
This of course could be a security risk so you need to check that the url submitted from the form to your servlet actually is residing on your page 🙂

Good Luck
/johan