用过smartupload的高手请进,在线等待!

databaseman 2004-09-03 10:59:43
用smartupload上传文件,同时想要传递参数过来,但是如果上一个页面的trans_at什么都不输入,
在下一个页面获取的时候变成啥了呢?
String trans_at_str = new String(su.getRequest().getParameter("trans_at").getBytes("ISO_8859_1"), "gb2312");
if (trans_at_str != ""){
out.print("aaaa");
}
if (trans_at_str != null){
out.print("bbbb");
}
结果什么都没有打印出来,谁遇到过这样地问题啊?解决马上给分!
...全文
129 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxt1013 2004-09-03
  • 打赏
  • 举报
回复
给你一个实例参考一下:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();

long id = 0;
String errmsg = "";
SmartUpload upload = new SmartUpload();
try {
upload.initialize(config, request, response );
upload.upload();

Request rq = upload.getRequest();
id = getCaseID(rq);
if (id < 0){
errmsg = MyUtil.toISO8859("aaaaaaaaaaa!");
getServletConfig().getServletContext().getRequestDispatcher("/casecollect.jsp?id="+id+"&errmsg="+errmsg).forward(request, response);
return;
}

Files files = upload.getFiles();
if(files == null || files.getCount() == 0 || files.getFile(0).getSize() == 0) {
errmsg = MyUtil.toISO8859("bbbbbbbbb!");
getServletConfig().getServletContext().getRequestDispatcher("/casecollect.jsp?id="+id+"&errmsg="+errmsg).forward(request, response);
return;
}
} catch (Exception e){

}
}
power17 2004-09-03
  • 打赏
  • 举报
回复
我不清楚为什么我的运行结果和你的不一样。我的代码是这样的:

_smartupload.html
<!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>
<table width="50%" border="1" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><div align="center">
<form name="form1" method="post" action="_smartupload.jsp" enctype="multipart/form-data">
<p>file1:
<input name="file" type="file" id="file">
</p>
<p> <input type="submit" name="Submit" value="提交">
</p>
</form>
</div></td>
</tr>
</table>
</body>
</html>


_smartupload.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="java.util.*,com.jspsmart.upload.*" %>
<!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>
<p>
<%! int i=0;%>
<%
try{
SmartUpload su=new SmartUpload();
//su.setMaxFileSize(4096);
su.initialize(pageContext);
su.upload();
String _name=su.getRequest().getParameter("file");
out.println(_name);
}catch(Exception e){}
%>
</p>
<p> </p>
</body>
</html>


按你说的去运行,结果是
null
你运行一下我的代码,看看结果是什么。
databaseman 2004-09-03
  • 打赏
  • 举报
回复
哈哈,多谢各位,打印出来啥也没有,应该就是"",结贴了,给分!
黑马 2004-09-03
  • 打赏
  • 举报
回复
不是smartupload的问题,先打印出来看看又没有值,再说
kingmaxno1 2004-09-03
  • 打赏
  • 举报
回复
1.trans_at_str == ""这么写是错的,要这样 "".equals(trans_at_str)写
2.你把你要的值打印一下试试
System.out.println(trans_at_str )
3.查一下smartupload关于request的源码,你可以用反编译器翻译一下
yangzuyu12 2004-09-03
  • 打赏
  • 举报
回复
String trans_at_str = new String(su.getRequest().getParameter("trans_at").getBytes("ISO_8859_1"), "gb2312");
if (trans_at_str.equals("")){
out.print("aaaa");
}
if (trans_at_str == null){
out.print("bbbb");
}
Jacky1206 2004-09-03
  • 打赏
  • 举报
回复
还有,比较空字符串不能用==要用equals("");
if (trans_at_str != null && trans_at_str.equals("")){
out.print("aaaa");
}
Jacky1206 2004-09-03
  • 打赏
  • 举报
回复
if (trans_at_str == ""){
out.print("aaaa");
}
if (trans_at_str == null){
out.print("bbbb");
}
如果以上都无打印,那么先打印出来看看
System.out.println("**************" + trans_at_str);
databaseman 2004-09-03
  • 打赏
  • 举报
回复
错了错了,是
用smartupload上传文件,同时想要传递参数过来,但是如果上一个页面的trans_at什么都不输入,
在下一个页面获取的时候变成啥了呢?
String trans_at_str = new String(su.getRequest().getParameter("trans_at").getBytes("ISO_8859_1"), "gb2312");
if (trans_at_str == ""){
out.print("aaaa");
}
if (trans_at_str == null){
out.print("bbbb");
}
结果什么都没有打印出来,谁遇到过这样地问题啊?解决马上给分!
databaseman 2004-09-03
  • 打赏
  • 举报
回复
用smartupload上传文件,同时想要传递参数过来,但是如果上一个页面的trans_at什么都不输入,
在下一个页面获取的时候变成啥了呢?
String trans_at_str = new String(su.getRequest().getParameter("trans_at").getBytes("ISO_8859_1"), "gb2312");
if (trans_at_str = ""){
out.print("aaaa");
}
if (trans_at_str = null){
out.print("bbbb");
}
结果什么都没有打印出来,谁遇到过这样地问题啊?解决马上给分!

81,094

社区成员

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

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