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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
punithaprConnect With a Mentor Commented:
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
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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
 
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
 
Tuan_JeanAuthor Commented:
Thank you. That works.
0
All Courses

From novice to tech pro — start learning today.