公文转换系统
12月9日:
登录界面:
function login() { var username=$("#username").val(); var password=$("#password").val(); if(username==""||password=="") alert("请将信息填写完整!"); else { $.post( "login_do", {username:username, password:password}, function(data){ if(data=="yes") { alert("成功登陆!"); window.location="mainpage.jsp"; } else alert("用户名或密码错误!或用户已被暂停使用!"); }, "text" ); } } function entermang() { var username=$("#username").val(); var password=$("#password").val(); if(username==""||password=="") alert("请将信息填写完整!"); else { $.post( "login_do", {username:username, password:password}, function(data){ if(data=="yes") { alert("成功登陆!"); window.location="backmainpage.jsp"; } else alert("用户名或密码错误!或用户已被暂停使用!"); }, "text" ); } }
package com.official.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.official.bean.Users; import com.official.util.DBUtil; /** * Servlet implementation class login_do */ @WebServlet("/login_do") public class login_do extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String username=request.getParameter("username"); String password=request.getParameter("password"); Users user=new Users(); user.setUsername(username); user.setPassword(password); if(DBUtil.log_isExist(user)) { Cookie cookie=new Cookie("username", username); cookie.setPath("/"); //设置存活时间 cookie.setMaxAge(60*60*24); response.addCookie(cookie); Users users=DBUtil.getUserByUsername(user); int pid=users.getPermissionId(); Cookie cookie2=new Cookie("pid", Integer.toString(pid)); cookie2.setPath("/"); cookie2.setMaxAge(60*60*24); response.addCookie(cookie2); response.getWriter().write("yes"); } else { response.getWriter().write("no"); } } }
文件:
1.文件的收入;
package com.official.servlet; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.official.bean.Doc; import com.official.util.DBUtil; /** * Servlet implementation class writedoc_do */ @WebServlet("/writedoc_do") public class writedoc_do extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String text=request.getParameter("text"); String user=request.getParameter("user"); String title=request.getParameter("title"); System.out.println(text); Date date = new Date(); SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String time=dateFormat.format(date).toString(); String path="E:\work_space\official-document\WebContent\text\"+title+"_"+user+"_"+time.split(":| ")[0]+time.split(":| ")[1]+time.split(":| ")[2]+time.split(":| ")[3]+".txt"; System.out.println(path); File file = new File(path); FileOutputStream fileOutputStream; Doc doc=new Doc(); doc.setTitle(title); doc.setOwner(user); doc.setReceiver("办公室"); doc.setTime(time); doc.setStatus(-1); doc.setResult(0); doc.setPlace(path); if(DBUtil.add_doc(doc)) { try { fileOutputStream = new FileOutputStream(file); try { fileOutputStream.write((text).getBytes()); fileOutputStream.close(); response.getWriter().write("yes"); } catch (IOException e) { // TODO 自动生成的 catch 块 response.getWriter().write("no"); e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO 自动生成的 catch 块 response.getWriter().write("no"); e.printStackTrace(); } } else { response.getWriter().write("no"); } } }