在用户注册界面,要上传一个用户的头像,那么怎么才能做到这个上传后的路径和这个用户绑定呢?
解决方案 »
- 求助 关于java 和 appleappstroe通信
- 初学JSP,请教一些名词
- filter能设置例外路径么?就是除了那个路径或文件其他都过滤
- 兄弟们!!帮啊,我有小三阳,要怎么样检查不出乙肝啊
- if(testLogin.equals("hasLogin"))有错吗?
- 求助关于jsp:useBean问题
- 在tomcat4.0中的sevlet怎么配置?(应该考到什么目录下面)写的javabean的编译后的class改放倒什么目录下?怎么用javabean??
- 如何将字符串数组转换为double或float型?!
- 用JAVA的IO怎么实现图形文件(GIF/JPG)的读写,100分奉送!
- 天哪!!为什么会这样??
- 关于struts分页和防灌水的随机验证码
- 国际化乱码问题(ResourceBundle)
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
// ActionMessages mess=new ActionMessages();
String dir=servlet.getServletContext().getRealPath("/upload");
File scfile=new File(dir);
if(!scfile.exists()){
scfile.mkdir();
}
HtmlFileForm hff=(HtmlFileForm)form;
FormFile file=hff.getFile();
String flname=file.getFileName();
if(flname==null||flname.equals("")){
this.setFileErrorMessage("sssss");
request.setAttribute("error1", this.fileErrorMessage);
return mapping.findForward("failure");
}
// ナミカマホトシ�タ獎ヘ
int imgType=flname.lastIndexOf(".");
String imgTypeStr=flname.substring(imgType);
//スォホトシ�テ逸ヲタ昕ノオアフ�ネユニレ+ヒ貍エハ�
String date=DNSUtility.getCurrentYeanMonthDay();
String[] dateStr=date.split("/");
String dateName=dateStr[0]+dateStr[1]+dateStr[2];
Random random = new Random();
int rdInt=random.nextInt(1000000000);
String rdStr=String.valueOf(rdInt);
String fname=dateName+rdStr+imgTypeStr;
//ア」エ豬スハ�センソ� String urlTemp="./upload/";
String picUrl=urlTemp+fname;
//ナミカマホトシ�エ。
if(file.getFileSize()>2097152){
this.setSizeErrorMessage("カヤイサニャヌ�イ鮓ヤト揵マエォオトヘシニャハヌキ�ネキ(ホトシ�メムセュウャケ�2M)!");
request.setAttribute("error2", this.sizeErrorMessage);
return mapping.findForward("failure");
}
// ナミカマホトシ�タ獎ヘ
// ア」エ�.swfホトシ�オスflashア� if(imgTypeStr.equals(".swf")){
String size=Integer.toString(file.getFileSize())+"bytes";
InputStream streamIn=file.getInputStream();
OutputStream streamOut=new FileOutputStream(dir+"/"+fname);
int bytesRead=0;
byte[] buffer=new byte[8192];
while((bytesRead=streamIn.read(buffer,0,8192))!=-1){
streamOut.write(buffer, 0, bytesRead);
}
streamOut.close();
streamIn.close();
hff.setFname(fname);
hff.setSize(size);
file.destroy();
this.pictureComponentsService.insertFlashUrl(picUrl);
return mapping.findForward("success");
}
if(!imgTypeStr.equals(".jpg")&&!imgTypeStr.equals(".gif")&&!imgTypeStr.equals(".jpeg")&&!imgTypeStr.equals(".png")&&!imgTypeStr.equals(".swf")){
this.setTypeErrorMessage("カヤイサニャヌ�イ鮓ヤト揵マエォオトヘシニャタ獎ヘ!");
request.setAttribute("error3",this.typeErrorMessage);
return mapping.findForward("failure");
}
String size=Integer.toString(file.getFileSize())+"bytes";
InputStream streamIn=file.getInputStream();
OutputStream streamOut=new FileOutputStream(dir+"/"+fname);
int bytesRead=0;
byte[] buffer=new byte[8192];
while((bytesRead=streamIn.read(buffer,0,8192))!=-1){
streamOut.write(buffer, 0, bytesRead);
}
streamOut.close();
streamIn.close();
hff.setFname(fname);
hff.setSize(size);
file.destroy();
this.pictureComponentsService.insertPicUrl(picUrl);
return mapping.findForward("success");
}
能有servlet+jsp实现的吗?
一般论坛里面的注册信息那里的用户名和头像的路径是怎么绑定的?