parsing parameter from child to parent window in JSP

I have two JSP i.e. course1.jsp and course2.jsp. I would want to find out how I could parse the parameter/value from child window to the parent window when the child window get closed.

What I am trying to do is actually a file upload process. The child windows will open for user to upload the file, and when close, the file name will be parse into the parent form for database update.  Is this something possible at all? or is there any other better approaches.

Thank you.

These are the two files:

--------course1.jsp ------------

Attach File <p>
<FORM name="courseForm" action="course2.jsp" method="post" enctype="multipart/form-data">
<TABLE cellSpacing=1 cellPadding=3 border=0 WIDTH=500>    
     <TR > 
        <TD>  
        <input type="text" NAME="f_file_name" size="30" VALUE="this value should be taken from child windows">
        <a href="course2.jsp" target="new"> get file name </a>
        <p>
         <INPUT class="buttons" TYPE="submit" NAME="submit" VALUE="Submit">
       </TD>
      </TR>
</TABLE>
</FORM>

---- course2.jsp -------

<%
 String filename = "this is the string needs to go back to parent windows when I click on close";
 %>
 <p>
 <a href="#" onClick=window.close();> close </a>
Tuan_JeanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodingExpertsCommented:
Hi Tuan,

change course1.jsp as

<FORM name="courseForm" action="course2.jsp" method="post" enctype="multipart/form-data">
<TABLE cellSpacing=1 cellPadding=3 border=0 WIDTH=500>    
     <TR > 
        <TD>  
            Attachment1
        </TD>
       <TD>
            <input type="file" value="Button" name="B3">            
       </TD>
      </TR>
</TABLE>
</FORM>
 
0
Tuan_JeanAuthor Commented:
Thank you for the prompt reply. The reason I use a link to move the attachment to another JSP is becuase some how the following structure does not work with multipart/form-data.

<% if (request.getParameter("action") == null ) { %>

 
<FORM name="courseForm" action="course2.jsp" method="post" enctype="multipart/form-data">
<TABLE cellSpacing=1 cellPadding=3 border=0 WIDTH=500>    
     <TR > 
        <TD>  
        <input type="text" NAME="f_file_name" size="30" VALUE="this value should be taken from child windows">
        <a href="course2.jsp" target="new"> get file name </a>
        <p>
        <INPUT class="buttons" TYPE="submit" NAME="submit" VALUE="Submit">
       </TD>
      </TR>
</TABLE>
</FORM>

 
<% } else if (request.getParameter("action").equals("Submit")) { %>


... Do the file upload and other activities
.. not sure why if I use multipart/form-data it will never come into this portion.

<%} %>  
     
0
CodingExpertsCommented:
Okay the best way around is to make Submit a link rather than a button. and on the click of the link call a javascript function that would submit the form.

-CE
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tuan_JeanAuthor Commented:
CE

So parsing a parameter from one window to another is an impossible thing? Thank you.
0
CodingExpertsCommented:
No it is not immposible .... but the problem would be that you'll have to manually write the file name on the pop up window, ther wouldnot be any browse button to locate the file.

Well if you want to do it that way all you have to do is in the action in course2.jsp refer to the course1.jsp page and in course1.jsp obtain the parameter from the request.

say if on course2.jsp the field was
<input type="text" name="filename" />

you can obtain the value  in course1.jsp as

<% String filename = request.getParameter("filename"); %>
0
punithaprCommented:
Hi Tuan_Jean

U can try the following .....
It works for me, Let me know .....
--------------- Course1.jsp -----------------
<script language=javascript>
function GetReason() {
var winWidth = 300;
var winHeight = 300;
var winLeft = (screen.width-winWidth)/2;
var winTop = (screen.height-winHeight)/2;
win1 = window.open("course2.jsp", "Course", +
"menubar=0,toolbar=0,resizable=1,scrollbars=1" +
",width=" + winWidth + ",height=" + winHeight +
",top="+winTop+",left="+winLeft);
}
function SetReason(reasonText) {
document.forms[0].reasonText.value = reasonText;
document.forms[0].submit();
}
</script>

<%
String filename = null;
if(request.getParameter("reasonText") != null)
{
filename = (String)request.getParameter("reasonText");
}
else
{
filename="";
}
%>
<form>
<input type=text name=reasonText value=<%=filename%>>
<input type=button name="btntype" value="Submit" onclick="GetReason()">
</form>

--------- Course2.jsp ----------
<script language=javascript>
function SubmitReason() {
window.opener.SetReason(document.forms[0].reasonText.value);
self.close();
}
</script>
<body onload=self.focus()>
<form>
<input name=reasonText type=radio value="Max">
<br><input type=button value="Submit" onclick="SubmitReason()">
</form>

Thanks
Punitha
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tuan_JeanAuthor Commented:
Thank you. That works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.