2

I have two JSP pages a.jsp and b.jsp. And a.jsp includes b.jsp

a.jsp

<jsp:include page="b.jsp" >
  <jsp:param name="pageName" value="create" />
</jsp:include>

I am able to pass the value of variable pageName to b.jsp where I retrieve it by

b.jsp

<h1>This is a ${param.pageName} page<br>
<input type="text" name="userInput">

Now I want to send the value in the input element userInput back to a.jsp ( I want to use b.jsp as a child page with three parent jsp pages and the entered value will be different for all three parent pages a.jsp, b.jsp and c.jsp)

<h1>The user input entered in the child jsp is :<>

How can I achieve this?

Rudrani Angira
  • 956
  • 2
  • 14
  • 28
  • 1
    Store it in the session. Store it in a cookie. Note that the user will not provide input until long after (in computing terms) the page is sent. – Elliott Frisch Jun 30 '19 at 22:55
  • @ElliottFrisch Can i just do something like `In parent request.setAttribute("myAttrName", initialvalue); In child JSP - request.setAttribute("myAttrName", newvalue); Then in parent JSP after the jsp:include of the child, get the value - String result = (String)request.getAttribute("myAttrName");` instead of putting in session or cookie? This is one of the suggested approaches here https://stackoverflow.com/questions/17796931/setting-parent-jsp-variables-in-child-jsp?rq=1 – Rudrani Angira Jun 30 '19 at 23:14
  • 1
    I don't see why not. Not sure what you're asking. – Elliott Frisch Jun 30 '19 at 23:22
  • This question is confusing. I guess you ultimately want to ask "How to show the user input entered?", then the answer is: "Add a submit button to the form and then you can show it with `${param.userInput}` after pressing the submit button". Nothing of this all is related to include files. You'd have had exactly the same problem when having everything in a single JSP page (which is in the end probably also much easier for you in order to unit-test and to formulate an understandable question). – BalusC Jul 02 '19 at 14:47

0 Answers0