基于javaweb+mysql的jsp+servlet高校学生会社团管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
前台:用户注册登陆、个人中心的管理(成立社团、加入的社团、申请加入社团、申请加入活动等)、社团列表、社团风采、社团活动、新闻列表以及留言板功能;
后台管理页面主要有:注册登陆、个人中心、系统管理(用户管理、角色管理、菜单管理、新闻管理、留言管理)、社团管理(财务管理、社团列表、社团风采、社团活动、活动申请、学生管理、社团申请)等几大块
前台
后台:
技术框架
JSP Servlet MySQL JDBC Tomcat CSS JavaScript jstl
基于javaweb+mysql的JSP+Servlet高校学生会社团管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)
}
//添加保存
protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String contextPath = request.getServletContext().getContextPath();
Role role = new Role();
//得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String savePath = this.getServletContext().getRealPath("/upload");
File file = new File(savePath);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
//消息提示
String msg = "";
try{
//使用Apache文件上传组件处理文件上传步骤:
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
role.setId(item.getString("UTF-8"));
message.setCreateStu(createStu);
request.setAttribute("createStu", createStu);
}
String auditType = request.getParameter("auditType");
if (auditType != null && auditType != "") {
message.setAuditType(auditType);
request.setAttribute("auditType", auditType);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = messageService.page(message, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/team/messageList.jsp").forward(request, response);
}
//form跳转页面
private void form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
Message message = new Message();
if (id!=null && id!="") {
message = messageService.getById(id);
}
request.setAttribute("message", message);
request.getRequestDispatcher("/views/team/messageForm.jsp").forward(request, response);
}
}
//注册
private void regit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Student student = new Student();
//上传到服务器硬盘上,保证重启tomcat不会丢失文件
//获取上传文件的路径
String savePath = this.getServletContext().getRealPath("/upload");
File file = new File(savePath);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
//消息提示
String msg = "";
try{
//使用Apache文件上传组件处理文件上传步骤:
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
student.setId(item.getString("UTF-8"));
}
}
if ("loginName".endsWith(name)) {
student.setLoginName(item.getString("UTF-8"));
for (Student s : studentService.findAll(new Student())) {
if((s.getLoginName()+"").equals(student.getLoginName())){
System.out.println(msg="帐号已存在!!!");
System.out.println(msg);
System.out.println(msg);
System.out.println(msg);
System.out.println(msg);
throw new RuntimeException(msg);
}
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
Student student = new Student();
//分页有关
Page<Student> page = new Page<Student>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String loginName = request.getParameter("loginName");
if (loginName != null && loginName != "") {
student.setLoginName(loginName);
request.setAttribute("loginName", loginName);
}
String loginPassword = request.getParameter("loginPassword");
if (loginPassword != null && loginPassword != "") {
student.setLoginPassword(loginPassword);
request.setAttribute("loginPassword", loginPassword);
}
String auditType = request.getParameter("auditType");
if (auditType != null && auditType != "") {
student.setAuditType(auditType);
request.setAttribute("auditType", auditType);
}
String stuName = request.getParameter("stuName");
if (stuName != null && stuName != "") {
student.setStuName(stuName);
request.setAttribute("stuName", stuName);
}
String sex = request.getParameter("sex");
if (sex != null && sex != "") {
student.setSex(sex);
request.setAttribute("sex", sex);
}
String schoolRoom = request.getParameter("schoolRoom");
if (schoolRoom != null && schoolRoom != "") {
student.setSchoolRoom(schoolRoom);
request.setAttribute("schoolRoom", schoolRoom);
}
String classRoom = request.getParameter("classRoom");
if (classRoom != null && classRoom != "") {
String name = request.getParameter("name");
String href = request.getParameter("href");
String target = request.getParameter("target");
String isShow = request.getParameter("isShow");
String sort = request.getParameter("sort");
String parentId = request.getParameter("parentId");
String parentIds = request.getParameter("parentIds");
String remarks = request.getParameter("remarks");
Menu menu = new Menu();
menu.setName(name);
menu.setHref(href);
menu.setTarget(target);
menu.setIsShow(isShow);
menu.setSort(sort);
menu.setParentId(parentId);
menu.setParentIds(parentIds);
menu.setRemarks(remarks);
menuService.add(menu);
response.sendRedirect(contextPath+"/menu?method=list");
}
//添加保存
protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Menu menu = new Menu();
//得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
String savePath = this.getServletContext().getRealPath("/upload");
File file = new File(savePath);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
//消息提示
String msg = "";
try{
//使用Apache文件上传组件处理文件上传步骤:
//1、创建一个DiskFileItemFactory工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2、创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(factory);
//解决上传文件名的中文乱码
upload.setHeaderEncoding("UTF-8");
//3、判断提交上来的数据是否是上传表单的数据
if(!ServletFileUpload.isMultipartContent(request)){
//按照传统方式获取数据
if (type!=null && "success".equals(type)) {
request.setAttribute("msg", "更新权限成功!");
}
request.getRequestDispatcher("/views/system/setMenuRole.jsp").forward(request, response);
}
/**
* 更新保存权限设置
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void saveMenuRole(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String roleId = request.getParameter("roleId");
request.setAttribute("roleId", roleId);
menuRoleDao.delete(roleId);
MenuRole menuRole = new MenuRole();
menuRole.setRoleId(roleId);
String[] parameterValues = request.getParameterValues("menuIds");
if (parameterValues!=null) {
for (String string : parameterValues) {
menuRole.setMenuId(string);
menuRoleDao.add(menuRole);
}
}
response.sendRedirect(contextPath+"/menu?method=setMenuRole&type=success&roleId="+roleId);
}
public static void sortList(List<Menu> list, List<Menu> sourcelist, String parentId, boolean cascade){
for (int i=0; i<sourcelist.size(); i++){
Menu e = sourcelist.get(i);
if (e.getParentId()!=null && e.getParentId()!=null
&& e.getParentId().equals(parentId)){
list.add(e);
if (cascade){
// 判断是否还有子节点, 有则继续获取子节点
for (int j=0; j<sourcelist.size(); j++){
Menu child = sourcelist.get(j);
if (child.getParentId()!=null && child.getParentId()!=null
&& child.getParentId().equals(e.getId())){
sortList(list, sourcelist, e.getId(), true);
break;
}
}
}
}
}
}
}
}
if ("newsType".endsWith(name)) {
siteNews.setNewsType(item.getString("UTF-8"));
}
if ("title".endsWith(name)) {
siteNews.setTitle(item.getString("UTF-8"));
}
if ("pic".endsWith(name)) {
siteNews.setPic(item.getString("UTF-8"));
}
if ("shortContent".endsWith(name)) {
siteNews.setShortContent(item.getString("UTF-8"));
}
if ("content".endsWith(name)) {
siteNews.setContent(item.getString("UTF-8"));
}
if ("createUser".endsWith(name)) {
siteNews.setCreateUser(item.getString("UTF-8"));
}
if ("createTime".endsWith(name)) {
if (StringUtils.isNotEmpty(item.getString("UTF-8"))) {
siteNews.setCreateTime(Timestamp.valueOf(item.getString("UTF-8")));
}else {
siteNews.setCreateTime(new Date());
}
}
if ("isRun".endsWith(name)) {
siteNews.setIsRun(item.getString("UTF-8"));
}
if ("belonTeam".endsWith(name)) {
siteNews.setBelonTeam(item.getString("UTF-8"));
}
@WebServlet("/f")
public class FrontController extends HttpServlet {
private static final long serialVersionUID = 1L;
private String contextPath = "";
TeamsDao teamsDao=new TeamsDao();
TeamsService teamsService = new TeamsServiceImpl();
SiteNewsService siteNewsService = new SiteNewsServiceImpl();
TeamApplayService teamApplayService = new TeamApplayServiceImpl();
StudentService studentService = new StudentServiceImpl();
ActiveStuService activeStuService = new ActiveStuServiceImpl();
MessageService messageService = new MessageServiceImpl();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
contextPath = request.getServletContext().getContextPath();
String method = request.getParameter("action");
request.setAttribute("method", method);
if ("detail".equals(method)) {
detail(request, response);
}else if ("teamDetail".equals(method)) {
teamDetail(request, response);
}else if ("applayLeader".equals(method)) {
applayLeader(request, response);
}else if ("regit".equals(method)) {
regit(request, response);
}else if ("login".equals(method)) {
login(request, response);
}else if ("applayTeam".equals(method)) {
applayTeam(request, response);
}else if ("logout".equals(method)) {
logout(request, response);
}else if ("applayAct".equals(method)) {
applayAct(request, response);
}else if ("applayBuildTeam".equals(method)) {
applayBuildTeam(request, response);
}else if ("userInfo".equals(method)) {
userInfo(request, response);
}else if ("getMyActApplay".equals(method)) {
getMyActApplay(request, response);
}else if ("getMyTeamApplay".equals(method)) {
getMyTeamApplay(request, response);
}else if ("siteNewsList".equals(method)) {
siteNewsList(request, response);
}else if ("getMyTeam".equals(method)) {
getMyTeam(request, response);
}else if ("delete".equals(method)) {
delete(request, response);
upperCase = false;
} else {
sb.append(c);
}
}
return sb.toString();
}
/**
* 驼峰命名法工具
* @return
* toCamelCase("hello_world") == "helloWorld"
* toCapitalizeCamelCase("hello_world") == "HelloWorld"
* toUnderScoreCase("helloWorld") = "hello_world"
*/
public static String toCapitalizeCamelCase(String s) {
if (s == null) {
return null;
}
s = toCamelCase(s);
return s.substring(0, 1).toUpperCase() + s.substring(1);
}
/**
* 驼峰命名法工具
* @return
* toCamelCase("hello_world") == "helloWorld"
* toCapitalizeCamelCase("hello_world") == "HelloWorld"
* toUnderScoreCase("helloWorld") = "hello_world"
*/
public static String toUnderScoreCase(String s) {
if (s == null) {
return null;
}
StringBuilder sb = new StringBuilder();
boolean upperCase = false;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
boolean nextUpperCase = true;
if (i < (s.length() - 1)) {
nextUpperCase = Character.isUpperCase(s.charAt(i + 1));
}
if ((i > 0) && Character.isUpperCase(c)) {
if (!upperCase || !nextUpperCase) {
sb.append(SEPARATOR);
}
String classRoom = request.getParameter("classRoom");
if (classRoom != null && classRoom != "") {
student.setClassRoom(classRoom);
request.setAttribute("classRoom", classRoom);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = studentService.page(student, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/team/studentList.jsp").forward(request, response);
}
//form跳转页面
private void form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
Student student = new Student();
if (id!=null && id!="") {
student = studentService.getById(id);
}
request.setAttribute("student", student);
request.getRequestDispatcher("/views/team/studentForm.jsp").forward(request, response);
}
}
/**
* 系统用户控制器servlet
* @version V1.0
*/
@WebServlet("/user")
public class UserController extends HttpServlet {
private static final long serialVersionUID = 1L;
UserDao userDao=new UserDao();
UserService userService = new UserServiceImpl();
RoleService roleService = new RoleServiceImpl();
MenuRoleDao menuRoleDao = new MenuRoleDao();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method");
if ("add".equals(method)) {
add(request,response);
}else if ("delete".equals(method)) {
delete(request, response);
}else if ("list".equals(method)) {
list(request, response);
}else if ("update".equals(method)) {
update(request, response);
}else if ("form".equals(method)) {
form(request, response);
}else if ("save".equals(method)) {
save(request, response);
}else if ("login".equals(method)) {
login(request, response);
stringBuffer.append(" '1')");
moneyManger.setSqlStr(stringBuffer.toString());
}
List<MoneyManger> moneys = moneyMangerService.findAll(moneyManger);
double zhichu = 0.0;
double shouru = 0.0;
for (MoneyManger moneyManger2 : moneys) {
if ("1".equals(moneyManger2.getType())) {
zhichu += moneyManger2.getMoney();
}else {
shouru += moneyManger2.getMoney();
}
}
request.setAttribute("zhichu", zhichu);
request.setAttribute("shouru", shouru);
request.getRequestDispatcher("/mui/welcome.jsp").forward(request, response);
}
//添加
private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String newsType = request.getParameter("newsType");
String title = request.getParameter("title");
String pic = request.getParameter("pic");
String shortContent = request.getParameter("shortContent");
String content = request.getParameter("content");
String createUser = request.getParameter("createUser");
String createTime = request.getParameter("createTime");
String isRun = request.getParameter("isRun");
String belonTeam = request.getParameter("belonTeam");
String isAudit = request.getParameter("isAudit");
SiteNews siteNews = new SiteNews();
siteNews.setNewsType(newsType);
siteNews.setTitle(title);
siteNews.setPic(pic);
siteNews.setShortContent(shortContent);
siteNews.setContent(content);
siteNews.setCreateUser(createUser);
siteNews.setIsRun(isRun);
siteNews.setBelonTeam(belonTeam);
siteNews.setIsAudit(isAudit);
siteNewsService.add(siteNews);
response.sendRedirect(contextPath+"/siteNews?method=list");
}
//添加保存
protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SiteNews siteNews = new SiteNews();
//这是上传到tomcat下,文件容易丢失
/* //得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全*/
String savePath = this.getServletContext().getRealPath("/upload");
user.setPic(request.getContextPath()+"/upload" + "/" + filename);
}
}
if (user.getId()!=null && !"".equals(user.getId())) {
user.setPassword(userService.getById(user.getId()).getPassword());
userService.update(user);
}else{
userService.add(user);
}
response.sendRedirect(contextPath+"/user?method=list");
}catch (Exception e) {
msg= "文件上传失败!";
e.printStackTrace();
request.setAttribute("msg",msg);
request.getRequestDispatcher("/views/system/userForm.jsp").forward(request, response);
}
}
//删除
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String contextPath = request.getServletContext().getContextPath();
String id = request.getParameter("id");
userService.delete(id);
response.sendRedirect(contextPath+"/user?method=list");
}
//修改
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String username = request.getParameter("username");
String password = request.getParameter("password");
String pic = request.getParameter("pic");
String role = request.getParameter("role");
String isBolck = request.getParameter("isBolck");
User user = new User();
user.setId(id);
user.setUsername(username);
user.setPassword(password);
user.setPic(pic);
user.setRole(role);
user.setIsBolck(isBolck);
userService.update(user);
request.setAttribute("user", user);
request.getRequestDispatcher("/views/system/userForm.jsp").forward(request, response);
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
byte buffer[] = new byte[1024];
//判断输入流中的数据是否已经读完的标识
int len = 0;
//循环将输入流读入到缓冲区当中,(len=in.read(buffer))>0就表示in里面还有数据
while((len=in.read(buffer))>0){
//使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
out.write(buffer, 0, len);
}
//关闭输入流
in.close();
//关闭输出流
out.close();
//删除处理文件上传时生成的临时文件
item.delete();
msg = "文件上传成功!";
siteNews.setPic(request.getContextPath()+"/upload" + "/" + filename);
}
}
if (siteNews.getId()!=null && !"".equals(siteNews.getId())) {
siteNewsService.update(siteNews);
}else{
String username = CurrentUserUtils.getCurrentUser(request).getUsername();
siteNews.setCreateUser(username);
siteNewsService.add(siteNews);
}
response.sendRedirect(contextPath+"/siteNews?method=list&newsType="+siteNews.getNewsType());
}catch (Exception e) {
msg= "文件上传失败!";
e.printStackTrace();
request.setAttribute("msg",msg);
request.getRequestDispatcher("/views/team/siteNewsForm.jsp").forward(request, response);
}
}
//删除
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String newsType = siteNewsService.getById(id).getNewsType();
siteNewsService.delete(id);
response.sendRedirect(contextPath+"/siteNews?method=list&newsType="+newsType);
}
//修改
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String newsType = request.getParameter("newsType");
if ("classRoom".endsWith(name)) {
student.setClassRoom(item.getString("UTF-8"));
}
if ("phone".endsWith(name)) {
student.setPhone(item.getString("UTF-8"));
}
if ("pic".endsWith(name)) {
student.setPic(item.getString("UTF-8"));
}
if ("remark".endsWith(name)) {
student.setRemark(item.getString("UTF-8"));
}
}else{//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
System.out.println(filename);
if(filename==null || filename.trim().equals("")){
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
filename = filename.substring(filename.lastIndexOf("\\")+1);
String suffix = filename.substring(filename.lastIndexOf("."));
filename=String.valueOf(System.currentTimeMillis()+suffix);
//获取item中的上传文件的输入流
InputStream in = item.getInputStream();
//创建一个文件输出流
FileOutputStream out = new FileOutputStream(savePath + "\\" + filename);
//创建一个缓冲区
byte buffer[] = new byte[1024];
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
activeStu.setId(item.getString("UTF-8"));
}
}
if ("activeId".endsWith(name)) {
activeStu.setActiveId(item.getString("UTF-8"));
}
if ("stuId".endsWith(name)) {
activeStu.setStuId(item.getString("UTF-8"));
}
if ("stuName".endsWith(name)) {
activeStu.setStuName(item.getString("UTF-8"));
}
if ("phone".endsWith(name)) {
activeStu.setPhone(item.getString("UTF-8"));
}
if ("type".endsWith(name)) {
activeStu.setType(item.getString("UTF-8"));
}
if ("isArrive".endsWith(name)) {
activeStu.setIsArrive(item.getString("UTF-8"));
}
}else{//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
System.out.println(filename);
if(filename==null || filename.trim().equals("")){
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
filename = filename.substring(filename.lastIndexOf("\\")+1);
//获取item中的上传文件的输入流
String suffix = filename.substring(filename.lastIndexOf("."));
filename=String.valueOf(System.currentTimeMillis()+suffix);
InputStream in = item.getInputStream();
//按照传统方式获取数据
return;
}
//4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
List<FileItem> list = upload.parseRequest(request);
for(FileItem item : list){
//如果fileitem中封装的是普通输入项的数据
if(item.isFormField()){
String name = item.getFieldName();
//解决普通输入项的数据的中文乱码问题
if ("id".endsWith(name)) {
if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
student.setId(item.getString("UTF-8"));
}
}
if ("loginName".endsWith(name)) {
student.setLoginName(item.getString("UTF-8"));
for (Student s : studentService.findAll(new Student())) {
if((s.getLoginName()+"").equals(student.getLoginName())){
System.out.println(msg="帐号已存在!!!");
System.out.println(msg);
System.out.println(msg);
System.out.println(msg);
System.out.println(msg);
throw new RuntimeException(msg);
}
}
}
if ("loginPassword".endsWith(name)) {
student.setLoginPassword(item.getString("UTF-8"));
}
if ("regitTime".endsWith(name)) {
student.setRegitTime(new Date());
}
if ("auditType".endsWith(name)) {
student.setAuditType(item.getString("UTF-8"));