当前位置: 代码迷 >> Java Web开发 >> [求助] session传值及数组求助?
  详细解决方案

[求助] session传值及数组求助?

热度:239   发布时间:2006-06-08 17:52:57.0
[求助] session传值及数组求助?

一共6个文件,用计数器显示输入成员数,id为第一页输入的成员总人数
Counter.java是个计数器类,我在第一个页面输入id,到第二个页面显示是第一个成员,在再第二个页面输入姓名,跳转到第三个页面,计数器加一,当成员序数不大于id时,example3e.jsp,
example4e_a.jsp两页面循环继续输入example4e_a.jsp同时还要循环接收前面输入的成员姓名,若大于id则清零,提示输入足够人数跳到example5e_a.jsp

简单说就是要循环输入多个成员信息,这里仅用name代表一个人,输完一个回过头再输第2个,最后一次性将所有数据提交数据库.id为总成员数.
哎,毕业设计就被这玩意卡着了

现在的问题是example5e_a.jsp打印出的成员姓名只有最后一个的,前面的都是null

帮忙看看了
example1e.jsp:
-----------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"import="java.sql.*,java.io.*"%>
<%@ page import="DBcon.dbconn"session="true"%>
<jsp:useBean id="DBcon"scope="page"class="DBcon.dbconn"/>
<p>请输入插入Ms SQL Server2000数据库的数据:</p>
<form name="form2" method="post" action="example2e.jsp">
<p>ID:
<input type="text" name="id">
</p>
<p>
<input type="submit" name="Submit" value="下一步">
</p>
</form>
----------------------------------------------
example2e.jsp
---------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"import="java.sql.*,java.io.*"%>
<%@ page import="sys.Counter"session="true"%>
<jsp:useBean id="counter"scope="page"class="sys.Counter" />
<p>请输入插入Ms SQL Server2000数据库的数据:</p>
<form name="form2" method="post" action="example3e.jsp">

<%
String id=request.getParameter("id");
session.setAttribute("id",id);
%>
<br>

<% if(id=="")
{%>
<script language="javascript">

alert("请输入id的正确值!");
</script>
<% }%>
<%
int intValue = 0;
try
{
intValue = Integer.parseInt(id);
}
catch(Exception e)
{
System.out.println("This string doesn't include a integer.");
// do something...
}
counter.Save(intValue);
out.println(counter.getSave());
%>人
<p>
<input type="submit" name="Submit" value="下一步">
</p>
</form>
-----------------------------------
example3e.jsp
-------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"import="java.sql.*,java.io.*"%>
<%@ page import="sys.Counter"session="true" %>
<jsp:useBean id="counter"scope="page"class="sys.Counter" />
<p>请输入插入Ms SQL Server2000数据库的数据:</p>
<form name="form1" method="post" action="example4e_a.jsp">
<p>name:
<input type="text" name="name">
</p>
这是第
<%
String id=(String)session.getAttribute("id");
out.println(counter.getCount());

%>位成员
<%
out.println(counter.getSave());%>
<p>
<input type="submit" name="Submit" value="继续输入姓名">
</p>

</form>
---------------------------------------------
example4e_a.jsp
-------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"import="java.sql.*,java.io.*"%>
<%@ page import="sys.Counter"session="true" %>
<jsp:useBean id="counter"scope="page"class="sys.Counter" />
<p>请输入插入Ms SQL Server2000数据库的数据:</p>
<form name="formtest" id="formtest" method="post" >

<%
int i=counter.getCount();
int j=counter.getSave()+1;
String name[]=new String[j];
if(i<j)
{ name[i]=request.getParameter("name");
out.print(name[i]+"||");
}
session.setAttribute("name",name);

out.println(counter.getCount());
out.println(counter.getSave());
counter.zeroCount(counter.getSave());
out.println(counter.getCount());
if(counter.getCount()==0)
{
out.println("你已经输入了全部成员!");
}
else
{
out.println("请继续输入下一位成员!");
}
counter.setCount();
out.println(counter.getCount());

%>
<p>
<input name="buttonA" id="buttonA" value="按钮A" type="button" onClick="submitA()">
</p>
<p>
<input name="buttonB" id="buttonB" value="按钮B" type="button" onClick="submitB()">
</p>
<script>
function submitA(){
formtest.action = "example3e.jsp";
formtest.submit();
}
function submitB(){
formtest.action = "example5e_a.jsp";
formtest.submit();
}
</script>
</form>
-----------------------------
example5e_a.jsp
--------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java"import="java.sql.*,java.io.*"%>
<%@ page import="sys.Counter"session="true" %>
<jsp:useBean id="counter"scope="page"class="sys.Counter" />
<p>请输入插入Ms SQL Server2000数据库的数据:</p>
<form name="formtest" id="formtest" method="post" >

<%

int j=counter.getSave();
String name[]=new String[j];
for(int i=counter.getCount();i<(j+1);i++)
{
name=(String[])session.getAttribute("name");
out.println(name[i]);
}
%>
<p>
<input type="submit" name="Submit" value="下一步">
</p>
</form>
-----------------------------------
Counter.java:
--------------------------------
package sys;
public class Counter
{
static int Count=1;
static int save;
static String zfc[]=new String[10];
public void Counter()
{
}

public static void Save(int i)
{
save=i;
}
public void addCount()
{
Count++;
}
public void setCount()
{
if(Count==0)
Count++;
}
public void zeroCount(int j)
{
if(Count>=j)
{
Count=0;
}
else
{
Count++;
}
}
public int getCount()
{
return Count;
}
public int getSave()
{
return save;
}
public void Zfc(String a)
{ int j=save;
int i=Count;
if(i<j+1)
{zfc[i]=a;

}
}
public String getZfc()
{
int i=Count;
return zfc[i];
}
}
----------------------------------------

[此贴子已经被作者于2006-6-8 18:53:37编辑过]

搜索更多相关主题的帖子: session  传值  

----------------解决方案--------------------------------------------------------
没有见对数据操作的语句
----------------解决方案--------------------------------------------------------
数据库


----------------解决方案--------------------------------------------------------
  相关解决方案