publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.setCharacterEncoding("gb2312");MultipartRequestmulti=new...
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
MultipartRequest multi = new MultipartRequest(request,path,10*1024*1024,"gb2312" ) ;
String name = multi.getParameter("name");
String pass = multi.getParameter("pass");
String sdate = multi.getParameter("sdate");
String edate = multi.getParameter("edate");
File file = multi.getFile("pic");
String filepath ="imgs/"+file.getName();
User user = new User();
boolean flag = user.zhuce(name,mdpass,filepath,sdate,edate); 插入数据库
if(flag){
response.sendRedirect("../login.jsp");
}else{
response.sendRedirect("../MyJsp.jsp");
}
}
String path="";
String picpath ="";
public void init(ServletConfig cfg) throws ServletException {
//获取web应用的决对路径
String abspath = cfg.getServletContext().getRealPath("/");
System.out.println("abs:"+abspath);
//获取保存图片目录的相对路径
picpath = cfg.getInitParameter("pic");
// 获取保存图片目录的绝对路径
this.path = abspath+picpath;
}
解释一下上面程序 这样图片就上传了吗 上传哪里去了
展开