📄 uploadstudphoto.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: UploadStudPhoto.java
package com.saintbo.servlet.student;
import com.jspsmart.upload.Files;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.saintbo.entity.student.TblStudent;
import com.saintbo.javabean.sys.SysResource;
import com.saintbo.javabean.sys.UserInfo;
import com.saintbo.servlet.MyExtendedServlet;
import com.saintbo.session.student.StudentSessionLocal;
import com.saintbo.session.student.StudentSessionLocalHome;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
public class UploadStudPhoto extends MyExtendedServlet
{
private static ServletConfig config;
public UploadStudPhoto()
{
}
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
UploadStudPhoto _tmp = this;
config = config;
}
public ServletConfig getServletConfig()
{
return config;
}
public void handle()
throws IOException, ServletException
{
UserInfo userInfo = (UserInfo)session.getAttribute("USERINFO");
int userAuthority = super.checkAuthority(userInfo, 1, 0);
if(userAuthority != 1)
return;
String studentID = "";
String errorMessage = "";
boolean result = false;
if(SysResource.getSysParamValByParamID(new Integer(128)) != null || "1".equals(SysResource.getSysParamValByParamID(new Integer(128))))
{
System.out.println(1);
SmartUpload smartUpload = new SmartUpload();
System.out.println(2);
smartUpload.initialize(config, req, res);
System.out.println(3);
try
{
smartUpload.upload();
Request smartRequest = smartUpload.getRequest();
studentID = smartRequest.getParameter("StudentID");
System.out.println("StudentID:" + studentID);
String photoName = "";
String photoFile = "";
TblStudent student = null;
if(studentID != null && !studentID.trim().equals(""))
{
InitialContext jndiContext = new InitialContext();
StudentSessionLocalHome home = (StudentSessionLocalHome)jndiContext.lookup("StudentSessionLocal");
StudentSessionLocal local = home.create();
System.out.println("get ejb");
student = local.getStudentByStudentID(studentID);
System.out.println("ejb end");
com.jspsmart.upload.File photo = smartUpload.getFiles().getFile(0);
photoName = photo.getFileName();
int index = photoName.indexOf(".");
photoName = photoName.substring(1, index);
photoFile = photo.getFileName();
String photoPath = "/upload/student/photo/";
photoFile = photoPath + photoFile;
String path = getServletContext().getRealPath("/") + photoPath;
File pathDir = new File(path);
if(!pathDir.exists())
pathDir.mkdirs();
System.out.println(path);
System.out.println(photoName);
System.out.println(photoFile);
File file = null;
if(!photo.isMissing())
{
System.out.println("save file");
com.jspsmart.upload.File _tmp = photo;
photo.saveAs(photoFile, 1);
System.out.println("save file end");
student.setPhotoName(photoName);
student.setPhotoFile(photoFile);
}
if(file != null)
file.delete();
local.remove();
jndiContext.close();
result = true;
} else
{
errorMessage = "传进来的学生学号不能为空.";
}
}
catch(Exception e)
{
errorMessage = "当上传学生照片时出现错误.";
System.out.println(errorMessage);
result = false;
e.printStackTrace();
}
} else
{
errorMessage = "您没有权利上传照片.";
}
if(result)
{
System.out.println(result);
getServletContext().getRequestDispatcher("/student/studentdetail.jsp?StudentID=" + studentID).forward(req, res);
} else
{
System.out.println("result:" + result);
session.setAttribute("ERRORMESSAGE", errorMessage);
getServletContext().getRequestDispatcher("/error/error.jsp").forward(req, res);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -