基于javaweb+mysql的jsp+servlet高校学生宿舍管理系统(java+mysql+jsp+servlet+tomcat)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet高校学生宿舍管理系统(java+mysql+jsp+servlet+tomcat)
管理员:
admin 123456
宿管员:
manager 123456
班主任:
teacher 123456
学生:
user1 123456
user2 123456
user3 123456
*学生可以注册、登录、修改详细资料、报修、水电费等
else if(method.equals("logout")){//从iframe页面退出登陆
session.removeAttribute("member");
session.removeAttribute("type");
request.getRequestDispatcher("login1.jsp").forward(request, response);
}
else if(method.equals("pagelogout")||method.equals("memberexit")){//从网页退出登陆
session.removeAttribute("member");
session.removeAttribute("type");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else{
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
/**
*
* 网站后台管理注册会员 查询 冻结 删除会员
*/
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
/**
* 会员注册、修改资料等
*
*/
public class MemberAction extends HttpServlet {
/**
* Constructor of the object.
*/
public MemberAction() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
return s1;
}
if(flag)
{
throw new IllegalArgumentException("The path is not a virtual path.");
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
if(i == 2)
{
if(flag)
{
if(m_denyPhysicalPath)
{
throw new IllegalArgumentException("Physical path is denied (1125).");
}
else
{
return s;
}
}
if(isVirtual(s1))
{
throw new IllegalArgumentException("The path is not a physical path.");
}
else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
else
{
return null;
}
}
public void uploadInFile(String s) throws IOException,SmartUploadException
{
//boolean flag = false;
*/
public class NewsAction extends HttpServlet {
private ServletConfig config;
/**
* Constructor of the object.
*/
public NewsAction() {
super();
}
final public void init(ServletConfig config) throws ServletException
{
this.config = config;
}
final public ServletConfig getServletConfig()
{
return config;
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
m_contentDisposition = s;
}
public void setTotalMaxFileSize(long l)
{
m_totalMaxFileSize = l;
}
public void setMaxFileSize(long l)
{
m_maxFileSize = l;
}
protected String getPhysicalPath(String s,int i) throws IOException
{
String s1 = ""; //new String();
String s2 = ""; //new String();
String s3 = ""; //new String();
boolean flag = false;
s3 = System.getProperty("file.separator");
if(s == null)
{
throw new IllegalArgumentException("There is no specified destination file (1140).");
}
if(s.equals(""))
{
throw new IllegalArgumentException("There is no specified destination file (1140).");
}
if(s.lastIndexOf("\\") >= 0)
{
s1 = s.substring(0,s.lastIndexOf("\\"));
s2 = s.substring(s.lastIndexOf("\\") + 1);
}
if(s.lastIndexOf("/") >= 0)
{
s1 = s.substring(0,s.lastIndexOf("/"));
s2 = s.substring(s.lastIndexOf("/") + 1);
}
s1 = s1.length() != 0 ? s1 : "/";
java.io.File file = new java.io.File(s1);
if(file.exists())
{
flag = true;
}
if(i == 0)
{
if(isVirtual(s1))
{
s1 = m_application.getRealPath(s1);
if(s1.endsWith(s3))
throws ServletException, IOException {
response.setContentType(Constant.CONTENTTYPE);
request.setCharacterEncoding(Constant.CHARACTERENCODING);
HttpSession session = request.getSession();
ComBean cBean = new ComBean();HzpBean hzb = new HzpBean();
String date2=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
String method = request.getParameter("method");
if(method.equals("delsp")){ //add 删除
String id = request.getParameter("id");
String sql="delete from tp where id='"+id+"'";
int flag = cBean.comUp(sql);
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/sp/index.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/sp/index.jsp").forward(request, response);
}
}
else if(method.equals("addgys")){//增加
//String xm = ""; String dz="";String dh="";String qq="";
String xm=request.getParameter("xm");
String dz=request.getParameter("dz");
String dh=request.getParameter("dh");
String qq=request.getParameter("qq");
int flag = cBean.comUp("insert into gys(xm,dz,dh,qq,sj) values('"+xm+"','"+dz+"','"+dh+"','"+qq+"','"+date2+"')");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/gys/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/gys/index.jsp").forward(request, response);
}
}
else if(method.equals("upgys")){//修改
String id = request.getParameter("id");
String xm=request.getParameter("xm");
public class HzpAction extends HttpServlet {
/**
* Constructor of the object.
*/
public HzpAction() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding(Constant.CHARACTERENCODING);
private String getContentType(String s)
{
String s1 = ""; // = new String();
String s2 = ""; // = new String();
int i = 0;
//boolean flag = false;
s1 = "Content-Type:";
i = s.indexOf(s1) + s1.length();
if(i != -1)
{
int j = s.length();
s2 = s.substring(i,j);
}
return s2;
}
private String getTypeMIME(String s)
{
//String s1 = new String();
int i = 0;
i = s.indexOf("/");
if(i != -1)
{
return s.substring(1,i);
}
else
{
return s;
}
}
private String getSubTypeMIME(String s)
{
//String s1 = new String();
//boolean flag = false;
int i = 0;
i = s.indexOf("/") + 1;
if(i != -1)
{
int j = s.length();
return s.substring(i,j);
}
else
{
return s;
}
}
private String getContentDisp(String s)
{
}
}catch(Exception e){
e.printStackTrace();
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
/**
* 网站公告
*
*/
public class AfficheAction extends HttpServlet {
if(k > 0 && l > 0)
{
s3 = s.substring(k,l);
}
}
return s3;
}
private String getFileExt(String s)
{
String s1; // = new String();
int i = 0;
int j = 0;
if(s == null)
{
return null;
}
i = s.lastIndexOf('.') + 1;
j = s.length();
s1 = s.substring(i,j);
if(s.lastIndexOf('.') > 0)
{
return s1;
}
else
{
return "";
}
}
private String getContentType(String s)
{
String s1 = ""; // = new String();
String s2 = ""; // = new String();
int i = 0;
//boolean flag = false;
s1 = "Content-Type:";
i = s.indexOf(s1) + s1.length();
if(i != -1)
{
int j = s.length();
s2 = s.substring(i,j);
}
return s2;
}
String s1 = getDataHeader();
m_currentIndex = m_currentIndex + 2;
boolean flag3 = s1.indexOf("filename") > 0;
String s3 = getDataFieldValue(s1,"name");
if(flag3)
{
s6 = getDataFieldValue(s1,"filename");
s4 = now+getFileName(s6);
s5 = getFileExt(s4);
s7 = getContentType(s1);
s8 = getContentDisp(s1);
s9 = getTypeMIME(s7);
s10 = getSubTypeMIME(s7);
}
getDataSection();
if(flag3 && s4.length() > 0)
{
if(m_deniedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is denied to be uploaded (1015).");
}
if(!m_allowedFilesList.isEmpty() && !m_allowedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is not allowed to be uploaded (1010).");
}
if(m_maxFileSize > 0L && (long)((m_endData - m_startData) + 1) > m_maxFileSize)
{
throw new SecurityException("Size exceeded for this file : " + s4 + " (1105).");
}
l += (m_endData - m_startData) + 1;
if(m_totalMaxFileSize > 0L && l > m_totalMaxFileSize)
{
throw new SecurityException("Total File Size exceeded (1110).");
}
}
if(flag3)
{
SmartFile file = new SmartFile();
file.setParent(this);
file.setFieldName(s3);
file.setFileName(s4);
file.setFileExt(s5);
file.setFilePathName(s6);
file.setIsMissing(s6.length() == 0);
file.setContentType(s7);
file.setContentDisp(s8);
file.setTypeMIME(s9);
file.setSubTypeMIME(s10);
if(s7.indexOf("application/x-macbinary") > 0)
request.getRequestDispatcher("member/bx/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("member/bx/index.jsp").forward(request, response);
}
}
else if(method.equals("upbx")){//修改
String id = request.getParameter("id");
String xm=request.getParameter("xm");
String dz=request.getParameter("dz");
String dh=request.getParameter("dh");
String qq=request.getParameter("qq");
int flag = cBean.comUp("update bx set xm='"+xm+"', dz='"+dz+"', dh='"+dh+"', qq='"+qq+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("member/bx/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("member/bx/index.jsp").forward(request, response);
}
}
else if(method.equals("delbx")){ //add 删除
String id = request.getParameter("id");
String sql="delete from bx where id='"+id+"'";
int flag = cBean.comUp(sql);
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("member/bx/index.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("member/bx/index.jsp").forward(request, response);
}
}
else if(method.equals("delbx2")){ //add 删除
String id = request.getParameter("id");
String sql="delete from bx where id='"+id+"'";
int flag = cBean.comUp(sql);
if(flag == Constant.SUCCESS){
public class MemberManageAction extends HttpServlet {
/**
* Constructor of the object.
*/
public MemberManageAction() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(Constant.CONTENTTYPE);
request.setCharacterEncoding(Constant.CHARACTERENCODING);
String sysdir = new SystemBean().getDir();
HttpSession session = request.getSession();
{
if(m_deniedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is denied to be uploaded (1015).");
}
if(!m_allowedFilesList.isEmpty() && !m_allowedFilesList.contains(s5))
{
throw new SecurityException("The extension of the file is not allowed to be uploaded (1010).");
}
if(m_maxFileSize > 0L && (long)((m_endData - m_startData) + 1) > m_maxFileSize)
{
throw new SecurityException("Size exceeded for this file : " + s4 + " (1105).");
}
l += (m_endData - m_startData) + 1;
if(m_totalMaxFileSize > 0L && l > m_totalMaxFileSize)
{
throw new SecurityException("Total File Size exceeded (1110).");
}
}
if(flag3)
{
SmartFile file = new SmartFile();
file.setParent(this);
file.setFieldName(s3);
file.setFileName(s4);
file.setFileExt(s5);
file.setFilePathName(s6);
file.setIsMissing(s6.length() == 0);
file.setContentType(s7);
file.setContentDisp(s8);
file.setTypeMIME(s9);
file.setSubTypeMIME(s10);
if(s7.indexOf("application/x-macbinary") > 0)
{
m_startData = m_startData + 128;
}
file.setSize((m_endData - m_startData) + 1);
file.setStartData(m_startData);
file.setEndData(m_endData);
m_files.addFile(file);
}
else
{
String s11 = new String(m_binArray,m_startData,(m_endData - m_startData) + 1);
String sm = Filter.escapeHTMLTags(mySmartUpload.getRequest().getParameter("sm").trim());
SmartFile file = mySmartUpload.getFiles().getFile(0);
String fileExt=file.getFileExt();
String path="/pic";
count = mySmartUpload.save(path);
int flag = cb.comUp("update tp set mc='"+mc+"', xc='"+xc+"',pic='"+path+"/"+file.getFileName()+"'," +
"sm='"+sm+"' where id='"+id+"'");
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/sp/index.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/sp/index.jsp").forward(request, response);
}
}
else{
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}catch(Exception ex){
ex.printStackTrace();
//request.getRequestDispatcher("error.jsp").forward(request, response);
}
}catch(Exception e){
e.printStackTrace();
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
/**
* 网站公告
else if(method.equals("DELCO")){//来自所有企业会员页面
request.getRequestDispatcher(sysdir+"/member/co.jsp").forward(request, response);
}
else if(method.equals("DELTODAY")){//来自今日注册会员页面
request.getRequestDispatcher(sysdir+"/member/today.jsp").forward(request, response);
}
else if(method.equals("DELALLCLOSE")){//来自所有冻结会员页面
request.getRequestDispatcher(sysdir+"/member/close.jsp").forward(request, response);
}
else if(method.equals("DELALLUSE")){//来自所有在用会员页面
request.getRequestDispatcher(sysdir+"/member/using.jsp").forward(request, response);
}
}
}
}
else if(method.equals("CLOSE")){
String id=request.getParameter("id").trim();
int flag=mmBean.closeMember(Integer.parseInt(id));
if(flag==Constant.SUCCESS){
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/member/person.jsp").forward(request, response);
}
else{
request.setAttribute("message", "系统维护中,请稍后再试!");
request.getRequestDispatcher("admin/member/person.jsp").forward(request, response);
}
}
else{
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
}catch(Exception e){
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
//Returning an array value stored in one of the object's fields exposes the internal representation of the object.? For classes shared by other untrusted classes, this could potentially be a security issue.? Returning a new copy of the array is better approach in many situations.
String[] vFileNames = new String[FileNames.length];
System.arraycopy(FileNames,0,vFileNames,0,FileNames.length);
return vFileNames;
}
public int getSize()
{
return m_totalBytes;
}
public byte getBinaryData(int i)
{
byte byte0;
try
{
byte0 = m_binArray[i];
}
catch(Exception exception)
{
throw new ArrayIndexOutOfBoundsException("Index out of range (1005).");
}
return byte0;
}
public SmartFiles getFiles()
{
return m_files;
}
public SmartRequest getRequest()
{
return m_formRequest;
}
public void downloadFile(String s) throws ServletException,IOException,SmartUploadException
{
downloadFile(s,null,null);
}
public void downloadFile(String s,String s1) throws ServletException,IOException,SmartUploadException,SmartUploadException
{
downloadFile(s,s1,null);
long l = 0L;
//String s = "";//new String();
//String s2 = "";//new String();
String s4 = ""; //new String();
String s5 = ""; //new String();
String s6 = ""; //new String();
String s7 = ""; //new String();
String s8 = ""; //new String();
String s9 = ""; //new String();
String s10 = ""; //new String();
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
int j;
for(;i < m_totalBytes;i += j)
{
try
{
m_request.getInputStream();
j = m_request.getInputStream().read(m_binArray,i,m_totalBytes - i);
}
catch(Exception exception)
{
throw new SmartUploadException("Unable to upload.");
}
}
for(;!flag1 && m_currentIndex < m_totalBytes;m_currentIndex++)
{
if(m_binArray[m_currentIndex] == 13)
{
flag1 = true;
}
else
{
m_boundary = m_boundary + (char)m_binArray[m_currentIndex];
}
}
if(m_currentIndex == 1)
{
return;