Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2017, 02:20 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get value from frame1 to frame2 with "input type = submit"

Hello everybody!

I just start learning servlet with eclipse and I have stuck on frameset.


I have 3 frames :


===Frame.jsp===
Code:
<%@ page language="java" contentType="text/html; charset=windows-31j"
    pageEncoding="windows-31j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
		<%@ page import="java.util.ArrayList" %>
		<%@ page import="java.io.PrintWriter" %>
		<%@ page import="javax.servlet.http.HttpServletRequest" %>
		<%@ page import="javax.servlet.http.HttpServletResponse" %>
		<%@ page import="javax.servlet.http.HttpServlet" %>
		<%@ page import="java.util.*" %>
		<%@ page import="javax.servlet.*" %>
		<%@ page import="javax.servlet.http.*" %>
		<%@ page import="java.io.*" %>
		<%@ page import="javax.servlet.http.HttpSession" %>
		<%@ page import="StudyC.HTMLFilter"%>
</head>

<frameset rows="25%,75%">
<frame src="HelloINPUT.jsp" NAME = "HelloINPUT"  noresize ="noresize">
<frame src="HelloOUTPUT.jsp" NAME = "HelloOUTPUT" >
</frameset>

<noframes>
<body>
EMPTY!
</body>
</noframes>

</html>


===HelloINPUT.jsp===

Code:
<%@ page language="java" contentType="text/html; charset=windows-31j"
    pageEncoding="windows-31j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
		<%@ page import="java.util.ArrayList" %>
		<%@ page import="java.io.PrintWriter" %>
		<%@ page import="javax.servlet.http.HttpServletRequest" %>
		<%@ page import="javax.servlet.http.HttpServletResponse" %>
		<%@ page import="javax.servlet.http.HttpServlet" %>
		<%@ page import="java.util.*" %>
		<%@ page import="javax.servlet.*" %>
		<%@ page import="javax.servlet.http.*" %>
		<%@ page import="java.io.*" %>
		<%@ page import="javax.servlet.http.HttpSession" %>
		<%@ page import="StudyC.HTMLFilter"%>
</head>
<body>
<center><b>INPUT</b></center>

<script language="JavaScript" type="text/javascript">

function validateForm() {
			var x = document.forms['myForm']['uname'].value;
			if (x == '') {
				alert('空です');
				return false;
			}
}

function SetSelectedValue()
{
    var selectedValue = validateForm();
    window.parent.HelloOUTPUT.frmSubmit.txtTest.value = selectedValue;
}

</script>
</head>

<body>
<form name='myForm'

onsubmit='SetSelectedValue()' target = "HelloOUTPUT" method='post'>
<input type='text' name='uname'>
<input type='submit' value='Click!'>

</form>

<%

String uname = request.getParameter("uname");
if (uname == null) {
	uname = "";
}

@SuppressWarnings("unchecked")
ArrayList<String> dataList = (ArrayList<String>)session.getAttribute("PreviousItems");
	if( dataList == null ) {
			dataList = new ArrayList<String>();
			session.setAttribute("PreviousItems", dataList);
}
dataList.add(uname);

if(dataList.isEmpty()) {
	out.print("<br>");
} else{
	dataList.removeAll(Arrays.asList("null",""));
    	if(dataList.isEmpty()) {
			out.print("<br>");

    	} else{
			int i = 0;
    		do{
			out.print(HTMLFilter.filter(dataList.get(i)) + "<br>");
    			i++;
    		}
    		while(i<dataList.size());
    	}
}

%>

</body>
</html>

===C18_HelloOUTPUT.jsp===

Code:
<%@ page language="java" contentType="text/html; charset=Windows-31j"
	pageEncoding="Windows-31j"%>

<html>
	<head>

		<%@ page import="java.util.ArrayList" %>
		<%@ page import="java.io.PrintWriter" %>
		<%@ page import="javax.servlet.http.HttpServletRequest" %>
		<%@ page import="javax.servlet.http.HttpServletResponse" %>
		<%@ page import="javax.servlet.http.HttpServlet" %>
		<%@ page import="java.util.*" %>
		<%@ page import="javax.servlet.*" %>
		<%@ page import="javax.servlet.http.*" %>
		<%@ page import="java.io.*" %>
		<%@ page import="javax.servlet.http.HttpSession" %>
		<%@ page import="StudyC.HTMLFilter"%>
		<%
		out.println("<center><b>OUTPUT</b></center>");
		%>

	</head>
		<body>

		</body>
</html>
Is there any other ways to get value from other frame with input type = submit?
Or should I change the input type?

Thank you!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Entering "e" as numeric input in Textbook ColinC BOOK: Excel VBA 24-Hour Trainer 2nd edition 9 October 5th, 2016 08:13 PM
class="x" to input control in Sell page doen't work? torr6420 BOOK: Beginning ASP.NET Web Pages with WebMatrix 2 December 5th, 2011 05:50 AM
"type" attribute in <script> tag Latinsteps BOOK: Beginning JavaScript 4th Edition 2 September 6th, 2011 01:29 AM
<input type="Checkbox" question??? RinoDM HTML Code Clinic 1 October 26th, 2009 06:00 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.