📄 processadd.jsp
字号:
<%@ page language="java" import="org.apache.commons.fileupload.*,java.io.*,com.buat.hr.users.User,com.buat.hr.users.UserDao,java.util.*" pageEncoding="GB18030"%>
<%
UserDao udao=new UserDao();
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(300000000);//设置允许用户上传的文件大小,单位:字节
fu.setSizeThreshold(4602);//设置最多只允许储存在内存的数据,单位:字节
fu.setRepositoryPath("f:\\winnt\\temp");// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
User user=new User();
try {
List filelist=(List)fu.parseRequest(request);
Iterator it=filelist.iterator();
while(it.hasNext()){
FileItem fileitem=(FileItem)it.next();
if(fileitem.isFormField()){//判断是否为表单内容
String s=fileitem.getFieldName();
String su=fileitem.getString();
if(s.equals("username")){
user.setUsername(su);
}else if(s.equals("passwords")){
user.setPasswords(su);
}else if(s.equals("gender")){
user.setGender(su);
}else if(s.equals("birthday")){
user.setBirthday(su);
System.out.println(user.getBirthday());
}else if(s.equals("isadmin")){
user.setIsadmin(su);
}else if(s.equals("introduce")){
user.setIntroduce(su);
}
}else {//文件上传 不是文本域
String pname=fileitem.getName();
long size=fileitem.getSize();
if((pname==null||pname.equals(""))&& size==0){
continue;
}
pname=pname.substring(pname.lastIndexOf("\\")+1,pname.length());
user.setPic("cellimgs/"+pname);
String path=this.getServletContext().getRealPath("cellimgs");
fileitem.write(new File(path+"\\"+pname));//将图片保存到指定的目录
}
}
} catch (Exception e) {
//System.out.println(e.getMessage());
}
%>
<html>
<head>
</head>
<body background="../bg.jpg">
<%
boolean flags=udao.addUser(user);
if(flags==true){
%>
<script type="text/javascript">
window.alert("新增成功!!!");
window.location.href("Scan.jsp");
</script>
<%
}
else{
%>
<script type="text/javascript">
window.alert("新增失败!!!");
window.location.href("Add.jsp");
</script>
<%
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -