我的一个上传文件的源码是:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" session="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%request.setCharacterEncoding("gb2312");
String str=response.encodeURL("Picupload.jsp");
%>
<table align="center" width="60%" bordercolor="#33FFFF">
<tr><td>个人照片上传:</td></tr>
<tr><td>
<p>choose the Picture to be uploaded:</p>
<form action="<%=str%>" method="post" enctype="multipart/form-data">
<input type="file" name="boy" size="45"></td></tr>
<tr><td><input type="text" name="Rank" class="input" maxlength="15">
请输入你的照片显示优先级(1-10);
</td></tr>
<tr><td><input type="submit" name="g" value="submit"></td></tr>
</form>
</table>
</body>
</html>
第二个页面Picupload.jsp为:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="mypack.*" %>
<%@ page import="java.io.*" %>
<jsp:useBean id="useDB" scope="application" class="mypack.UseDB"/>
<html>
<body>
<% request.setCharacterEncoding("gb2312");
String Rank=request.getParameter("Rank");
String userid=(String)session.getAttribute("USERID");
out.println(Rank);
String tempfilename=(String)session.getId();
File f1=new File("D:\\study software\\Tomcat 5.0\\webapps\\HomeT\\temp",tempfilename);
int n;
try
{
InputStream in=request.getInputStream();
BufferedInputStream my_in=new BufferedInputStream(in);
FileOutputStream fout=new FileOutputStream(f1);
BufferedOutputStream my_out=new BufferedOutputStream(fout);
byte[] b=new byte[10000];
while((n=my_in.read(b))!=-1)
{
my_out.write(b,0,n);
}
my_out.flush();
my_out.close();
fout.close();
my_in.close();
in.close();
out.print("文件上传成功!<br>");
}
catch(IOException e)
{
out.print("文件上传失败!");
}
try
{
RandomAccessFile random1=new RandomAccessFile(f1,"r");
random1.readLine();
String filename=random1.readLine();
byte[] b=filename.getBytes("ISO-8859-1");
filename=new String(b);
int pointer=filename.lastIndexOf('\\');
filename=filename.substring(pointer+1,filename.length()-1);
File f2=new File("D:\\study software\\Tomcat 5.0\\webapps\\HomeT\\user\\pic",filename);
RandomAccessFile random2=new RandomAccessFile(f2,"rw");
random1.seek(0);
for(int i=1; i<=4; i++)
{
String tempstr=random1.readLine();
}
long startPoint=random1.getFilePointer();
random1.seek(random1.length());
long mark=random1.getFilePointer();
int j=0;
long endPoint=0;
while((mark>=0)&&(j<=5))
{
mark--;
random1.seek(mark);
n=random1.readByte();
if(n=='\n')
{
j++;
endPoint=random1.getFilePointer();
}
}
long length=endPoint-startPoint+1;
int order=(int)(length/10000);
int left=(int)(length%10000);
byte[] c=new byte[10000];
random1.seek(startPoint);
for(int i=0; i<order; i++)
{
random1.read(c);
random2.write(c);
}
random1.read(c,0,left);
random2.write(c,0,left);
random1.close();
random2.close();
f1.delete();
out.print("文件更新成功!");
String reg="insert into UserImg(UserID,UserImgName,Rank) values("+userid+",'"+filename+"',"+Rank+")";
Connection conn=useDB.getConnection();
PreparedStatement stmt=conn.prepareStatement(reg);
stmt.executeUpdate();
useDB.closePrepStmt(stmt);
useDB.closeConnection(conn);
}
catch(Exception e)
{
out.print("文件更新失败!");
}
%>
</body>
</html>
但是,第二张页面的String Rank=request.getParameter("Rank");获得的值始终为:null;为什么?