JSP中如何在两个页面之间传递变量???在线等,急!!!

Explorerwg 2003-08-20 07:46:11
JSP中如何在两个页面之间传递变量???在线等,急!!!
在第一个页面的下拉框中要选择一种类型,然后选择相关的文件,在提交,第二个页面中,要用选择的类型进行判断,选择提交文件的存放地方!!!
请问如何解决???
最好给一个例子!!!
谢谢了!!!!!!!
...全文
699 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
younggone 2003-08-22
  • 打赏
  • 举报
回复
用applicaton.setattribute(name value)
另一个页面applicaton.getattribute(name value)
这种变量少用的好 嘿嘿
mickey_uuu 2003-08-22
  • 打赏
  • 举报
回复
你两个页面一样吗?

upload1.jsp页面:
<select name="Type1" size="1" id="Type1" >
upload.jsp页面:
String type = request.getParameter("Type1");

我这正常着呀!
Geranium 2003-08-22
  • 打赏
  • 举报
回复
页面2相应的也要改动啦,都改了吧?
Explorerwg 2003-08-22
  • 打赏
  • 举报
回复
to: mickey_uuu() 我已经试过了,不行啊!!!
bellhurry2003 2003-08-22
  • 打赏
  • 举报
回复
你的String类型的变量没有new ,所以是null值。
mickey_uuu 2003-08-22
  • 打赏
  • 举报
回复
你把“Type”换成“type1”就可以拉
Explorerwg 2003-08-22
  • 打赏
  • 举报
回复
to Geranium(天使消失的街道) 没有啊!!!是一个文件的路径,eg:E:\uploadfile\Images
Geranium 2003-08-22
  • 打赏
  • 举报
回复
Type传过来的字符串中有中文吧?
Geranium 2003-08-22
  • 打赏
  • 举报
回复
ACTION="upload.jsp"
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
to mickey_uuu() 仍然报同样的错啊!!!!
java.lang.NullPointerException
at _programe._uploadfile._upload__jsp._jspService(/programe/uploadFile/upload.jsp:63)

Explorer22 2003-08-22
  • 打赏
  • 举报
回复

to wantvictory()能够给一个用Session的例子吗???
mickey_uuu 2003-08-22
  • 打赏
  • 举报
回复
将<select name="Type" size="1" > 换成 <select name="Type" size="1" id="Type"> 试试
wantvictory 2003-08-22
  • 打赏
  • 举报
回复
Session就可以啦
Explorerwg 2003-08-22
  • 打赏
  • 举报
回复
各位帮忙看一下:
第一个页面的代码:upload1.jsp

<%@ page contentType="text/html; charset=gb2312"
import="java.util.Date ,java.io.*,java.lang.*,java.text.SimpleDateFormat"%>
<HTML>
<BODY BGCOLOR="white">

<H1 align="center">图片、电影、音乐、新闻上传</H1>
<HR>

<FORM METHOD="POST" ACTION="/programe/uploadFile/upload.jsp" ENCTYPE="multipart/form-data">
<select name="Type" size="1" > //*****这是要传送的值“Type"********
<%

String path="";

path = request.getRealPath("./");

File d = new File(path);
//建立代表目前目录位置的File件, 并由d件变数引用

File list[] = d.listFiles();
//取得代表目录中所有文件的File件阵列
int j=list.length-3;
int i =0;
while(j>0)
{

%>
<option value="<%=list[i]%>"><%=list[i]%></option>
<%
i++;
j--;
}
%>
</select>
<select name="Year" size="1">
<%
Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String sToday = format.format(today);
int lToday = Integer.parseInt(sToday);
int w = lToday%10000;
int ww=(lToday-w)/10000;

%>
<option value="<%=String.valueOf(ww)%>"><%=String.valueOf( ww)%></option>
</select>
<select name="Month" size="1">
<%
for(int month=1;month<=12;month++)
{
%>
<option value="<%=String.valueOf(month)%>"><%=String.valueOf( month)%></option>
<%
}
%>
</select>
<select name="Day" size="1">
<%
for(int day=1;day<=31;day++)
{
%>
<option value="<%=String.valueOf(day)%>"><%=String.valueOf(day)%></option>
<%
}
%>
</select>

<br>
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

</BODY>
</HTML>

第二个页面的代码:upload.jsp
<%@ page contentType="text/html; charset=gb2312" language="java"
import="com.jspsmart.upload.*,java.io.File,java.lang.*,java.util.Date,java.text.SimpleDateFormat"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />


<HTML>
<head>
<title>Images,Movies,Music,News UpLoaded</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<BODY BGCOLOR="white">

<H1 align="center">Images,Movies,Music,News UpLoaded</H1>
<HR>

<%

String type = request.getParameter("Type"); //********这是接收这个传送的值******
//String year = request.getParameter("Year");
//String month =request.getParameter("Month");
//String day = request.getParameter("Day");
out.println(type);

String path="";

path = request.getRealPath("./");

File d = new File(path);
//建立代表目前目录位置的File件, 并由d件变数引用

File list[] = d.listFiles();
//取得代表目录中所有文件的File件阵列
%>

<%
// Variables
int count=0;

// Initialization
mySmartUpload.initialize(pageContext);

// Only allow txt or htm files
mySmartUpload.setAllowedFilesList(" gif,jpg,swf,txt");

// DeniedFilesList can also be used :
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");

// Deny physical path
// mySmartUpload.setDenyPhysicalPath(true);

// Only allow files smaller than 2000000 bytes
mySmartUpload.setMaxFileSize(2000000);

// Deny upload if the total fila size is greater than 800000 bytes
mySmartUpload.setTotalMaxFileSize(800000);

// Upload
mySmartUpload.upload();

//look for file path ,if there is nothing ,create file path
File myFilePath = new File(type);
if(!myFilePath.exists())
myFilePath.mkdir();

String nextFilePath="";
nextFilePath = request.getRealPath("myFilePath/");


Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sToday = format.format(today);



String fileName =sToday;
File myFile = new File(nextFilePath+"/"+fileName);
if(!myFile.exists())
myFile.mkdir();
String filePath = nextFilePath+"/"+fileName;

// Save the files with their original names in a virtual path of the web server
try {

count = mySmartUpload.save(filePath, mySmartUpload.SAVE_VIRTUAL);

} catch (Exception e){

out.println("<b>Wrong selection : </b>" + e.toString());

}

// Display the number of files uploaded
out.println(count + " file(s) uploaded.");

%>


<table width="85%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td colspan="8">在<Font color = red><%= path%></Font>目录下的文件 一共有 <font color="#FF0000"><%=list.length%></font>
个文件或目录  <a href="javascript:history.back(1)">返回</a>   <a href="javascript:location.reload()">刷新</a> </td>
</tr>
</table>
<hr>

<table width="1000" height="150"border="0" align="center" cellpadding="3" cellspacing="0">
<%
for(int i=0; i <list.length/5; i++)
{
%>
<tr >
<%
for(int j=0;j<5;j++)
{
File f = new File(path,list[i*5+j].getName());
String file="";

file=list[i*5+j].getName();

//out.print(file.toString());
%>
<td align="center" width="120" height="150">
<a href="<%=file%>" target="_self"><img src="<%=file%>" width="120" height="150" name="<%=file.toString()%>" title="<%=file.toString()%>" ></a>
<a href="<%=file%>" target="_parent"><%=file%></a>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
<BR>
<a href="javascript:history.back(1)">Back</a>
</BODY>
</HTML>
大家帮忙看看为什么传过来的值接收后为空????在线等!!!!急啊!!!!!!!!!!!!


Explorerwg 2003-08-20
  • 打赏
  • 举报
回复
上面是一个朋友,发的消息,我放在这里保留!!!
谢谢各位了!!!
znjq1001 2003-08-20
  • 打赏
  • 举报
回复
2.0? 没用过,赶快看 :)
Explorerwg 2003-08-20
  • 打赏
  • 举报
回复
1 在一个Form中写一个Select,假定为Name1,将Form的Action设置为2.jsp
2 选择后,提交。
3 在另外一个叶面2.jsp中,用Request.getParameter("Name1")对这个值进行读取。
mechiland 2003-08-20
  • 打赏
  • 举报
回复
如果你使用JSP2.0,直接使用${param.id}或者${param["id"]}就行了。
Explorerwg 2003-08-20
  • 打赏
  • 举报
回复
用session,可以说的详细一点吗?能给一个例子吗???
谢谢啦!!!!!!
znjq1001 2003-08-20
  • 打赏
  • 举报
回复
如果只是页面之间传递参数,就没必要用session,占用内存,也不安全。
加载更多回复(6)

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧