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

Search screen with results

Sudhin_Baru
Level 2
Level 2

Hi,

 Is there anyway I can post from one JSP and capture the results in another JSP using CQ5?

I've a text box with a button in say component A.JSP. I used a template..etc http://localhost/...../Search.html

Now I want to capture the textbox value and search it in the SearchResults.html against a database. How can I call the SearchResults.html (say component B.JSP) on Submit button click from Search.html?

If I use the entire URL in the form action. I am getting the left nav bar multiple times in the SearchResults.html

Thanks,

Sudhin

1 Accepted Solution
Ojjis
Correct answer by
Level 7
Level 7

There's probably a huge number ways this can be achieved. Together with Scotts suggestion I'll throw some other ones in as well: 

  • You could either create you own search servlet which you post to from A and have it redirect the checked and validated values to B (guessing you want to have some validation/control over what is entered in the box and so on). This servlet would then maybe listen to a special resourceType  or path
  • Or you could (provided that there would be small text fragments from the box and a s tiny set of input fields) just call page B from page A with a querystring called something like "text" which would lead to B.html?text=mytext. Then you'll simply handle those query parameters in that jsp.

Hope that you'll find some way that suits you
/Johan

View solution in original post

4 Replies
smacdonald2008
Level 10
Level 10

In your A.JSP -- you can get the values (from controls in A.JSP) and send these values to B.JSP.

For example - user enters values into A.JSP and you want to get these values to B.JSP. That is no issue with CQ. See this community article:

http://scottsdigitalcommunity.blogspot.ca/2012/05/using-jsonwriter-objects-to-display.html

IN this article B.JSP would be lookup.json.jsp. A.JSP would be templateJSON.jsp.

Ojjis
Correct answer by
Level 7
Level 7

There's probably a huge number ways this can be achieved. Together with Scotts suggestion I'll throw some other ones in as well: 

  • You could either create you own search servlet which you post to from A and have it redirect the checked and validated values to B (guessing you want to have some validation/control over what is entered in the box and so on). This servlet would then maybe listen to a special resourceType  or path
  • Or you could (provided that there would be small text fragments from the box and a s tiny set of input fields) just call page B from page A with a querystring called something like "text" which would lead to B.html?text=mytext. Then you'll simply handle those query parameters in that jsp.

Hope that you'll find some way that suits you
/Johan

View solution in original post

Sudhin_Baru
Level 2
Level 2

Hi,

I have URL

http://localhost:4502/content/myuhcdental/membersearch.html

Now when I post it, I want it display the results on the same screen. Below is my java code, I want it to display as

http://localhost:4502/content/myuhcdental/membersearch.html?txtmemId=2

I made a small java program which in turn calls a database. Have an OSGI bundle etc..

I have a method which queries the database - getMember(x). --> This is working fine.

 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@include file="/libs/foundation/global.jsp"%> <%@ page import="java.sql.Connection" %> <%@ page import="java.sql.Statement" %> <%@ page import="com.adobe.test.DataService" %> <%@ page import="java.sql.ResultSet"%> <% //id = Integer.parseInt(request.getParameter("txtSearch")); int myid =2; //  myid = Integer.parseInt(memberid); %> <% DataService ds = new DataService(); %> <script type="text/javascript"> function doSubmit(){ var txtval = document.getElementById("txtMemid").value; if (txtval != null){ alert('in submit ' + txtval); form1.action = "membersearch.html?txtMemid=" + txtval; alert('action' + form1.action); document.getElementById("form1").submit(); } } </script> <form method="GET" id="form1"> <% String  memberid = request.getParameter("txtMemid"); %> <input type="text" id="txtMemid"></input> <input type="Submit" value="Search" onclick=doSubmit()></input> <h3> Hello:<%=ds.getMember(memberid)%> + you entered: <%= memberid %> end</h3> </form>
Sudhin_Baru
Level 2
Level 2

I just had to add

window.location.replace("membersearch.html?txtMemid=" + txtval);