一、完成的内容:
1.实现了用户登录系统的基本操作,可判断登录成功、密码错误和用户名不存在等情况并给出提示,可以实现不同的用户登录后所看到的界面功能不同。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <style> #top{ border: 1px solid black; 500px; height: 75px; font-size: 50px; text-align: center; margin: auto; padding-top: 25px; background-color: gainsboro ; } #one{ /*border: 1px solid black;*/ 500px; height:auto; background-color: ghostwhite; margin: auto; } #two{ border: 1px solid black; 500px; height: 250px; text-align: center; margin: auto; background-color: ghostwhite; } </style> </head> <body> <form action="Servlet" method="post"> <div id="top"><b><i>登录界面</i></b></div> <div id="one"> <div id="two"> <br /> <br /> 用户名: <input type="text" id="" name="username" /><br /> <br/><br /> 密 码: <input type="password" id="" name="password"/><br /> <br /><br /> <input type="submit" id="enter" name="enter" value="登录"/> <input type="button" id="zhuce" name="" value="注册" /> </div> </div> </form> <% if(request.getParameter("result")!=null&&request.getParameter("result").equals("yes")) { %> <script> alert("登录成功!"); window.location="main.jsp"; </script> <%} else if(request.getParameter("result")!=null&&request.getParameter("result").equals("no")) {%> <script> alert("用户名不存在!"); window.location="Enter.jsp"; </script> <%} else if(request.getParameter("result")!=null&&request.getParameter("result").equals("ERROR")){ %> <script> alert("密码错误!"); window.location="Enter.jsp"; </script> <%} %> </body> </html>
package dButil; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.security.auth.message.callback.PrivateKeyCallback.Request; import domain.Enter; public class DBUtil { public static final String connectionURL="jdbc:mysql://localhost:3306/big-text?useUnicode=true&characterEncoding=GB18030&useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true"; public static final String username="root"; public static final String psw="123456"; static Connection connection; static ResultSet rSet; static PreparedStatement sql; public static Connection getConnection() { try { Class.forName("com.mysql.cj.jdbc.Driver"); System.out.println("数据库连接成功"); return DriverManager.getConnection(connectionURL, username, psw); } catch (Exception e) { // TODO: handle exception System.out.println("数据库连接失败"); e.printStackTrace(); } return null; } //数据库连接 public static boolean search(String name)//查 { try { connection=getConnection(); sql=connection.prepareStatement("select * from enter where username='"+name+"'"); System.out.println(sql); rSet=sql.executeQuery(); rSet.next(); int aid =rSet.getInt(2); String password=rSet.getString(4); Enter.setAid(aid); Enter.setPassword(password); //System.out.println(Enter.getPassword()); System.out.println(rSet.getString(1)+" "+rSet.getString(2)+" "+rSet.getString(3)+" "+rSet.getString(4)+" "+rSet.getString(5)+""+rSet.getString(6)); return true; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return false ; } } public static void main(String[] args) { search("hostdirector"); } }
package Servlet; import java.io.IOException; 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 org.eclipse.jdt.internal.compiler.ast.DoubleLiteral; import com.sun.org.apache.xml.internal.serializer.ElemDesc; import dButil.DBUtil; import domain.Enter; /** * Servlet implementation class Servlet */ @WebServlet("/Servlet") public class Servlet extends HttpServlet { private static final long serialVersionUID = 1L; public static String username; public static String password; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); //if (request.getParameter("na").equals("enter")) { username=request.getParameter("username"); password=request.getParameter("password"); //System.out.println(password); boolean a= DBUtil.search(username); System.out.println(a); if(a==true) { System.out.println(Enter.getPassword()); if(Enter.getPassword().equals(password)) { request.getRequestDispatcher("Enter.jsp?result=yes").forward(request,response); System.out.println("登陆成功"); } else { request.getRequestDispatcher("Enter.jsp?result=ERROR").forward(request,response); System.out.println("密码错误 !"); } } else if(a==false) { request.getRequestDispatcher("Enter.jsp?result=no").forward(request, response); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
package domain; public class Enter { public static String name; public static String password; public static int aid; public static String job; public static String start ; public static String getName() { return name; } public static void setName(String name) { Enter.name = name; } public static String getPassword() { return password; } public static void setPassword(String password) { Enter.password = password; } public static int getAid() { return aid; } public static void setAid(int aid) { Enter.aid = aid; } public static String getJob() { return job; } public static void setJob(String job) { Enter.job = job; } public static String getStart() { return start; } public static void setStart(String start) { Enter.start = start; } }
main.jsp
<%@page import="domain.Enter"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <style> div{ border: 1px solid black; 400px; height: 50px; background-color: greenyellow; text-align: center; font-size:25px ; } a{ text-decoration: none; } </style> <script type="text/javascript"> function maketext() { window.location="writedoc.jsp"; } </script> </head> <body> <div style=" 1500px; height: 1000px; margin: auto; background-color: ghostwhite;"> <% if(Enter.getAid()==1) { System.out.println(Enter.getAid()); %> <div id="top" style=" 1500px;height: 100px; background-color: gainsboro;text-align: center; font-size: 75px;"> 功能界面 </div> <div style="height:50px;"><font color="red" size="6">功能操作</font> </div> <div ><a href="#">审签公文</a></div> <div ><a href="#">浏览已发所有公文</a></div> <div ><a href="#">查询公文</a></div> <%} else if(Enter.getAid()==2){ %> <div id="top" style=" 1500px;height: 100px; background-color: gainsboro;text-align: center; font-size: 75px;"> 功能界面 </div> <div style="height:50px;"><font color="red" size="6">功能操作</font> </div> <div ><a href="#">审核公文</a></div> <div><a href="#">浏览已发所有公文</a></div> <div ><a href="#">查询公文</a></div> <% } else if(Enter.getAid()>=4&&Enter.getAid()<=9) { %> <div id="top" style=" 1500px;height: 100px; background-color: gainsboro;text-align: center; font-size: 75px;"> 功能界面 </div> <div id="0" style="height:50px;"><font color="red" size="6">功能操作</font> </div> <div id="1"><a href="writedoc.jsp"><font size="5px">公文拟制</font></a></div> <div id="2"><a href="#">签收公文</a></div> <div id="3"><a href="#">浏览公文</a></div> <% } else if(Enter.getAid()==3){ %> <div id="top" style=" 1500px;height: 100px; background-color: gainsboro;text-align: center; font-size: 75px;"> 功能界面 </div> <div id="0" style="height:50px;"><font color="red" size="6">功能操作</font> </div> <div id="4"><a href="#">修改公文</a></div> <div id="5"><a href="#">公文流转</a></div> <div id="6"><a href="#">删除公文</a></div> <div id="7"><a href="#">公文发送</a></div> <%} else if(Enter.getAid()==10){%> <div id="top" style=" 1500px;height: 100px; background-color: gainsboro;text-align: center; font-size: 75px;"> 功能界面 </div> <div id="0" style="height:50px;"><font color="red" size="6">功能操作</font> </div> <div id="12"><a href="#">用户管理</a></div> <div id="13"><a href="#">角色管理</a></div> <div id="10"><a href="#">公文流转流程管理</a></div> <%} %> </div> </body> </html>
2.实现了部门的文件拟制功能
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <style> textarea{ 100%; height:500px; } .btnbag{ 100%; text-align:center; } .btn{ 150px; height:40px; border:0px; border-radius:5px; background-color:orange; color:black; margin-left:auto; margin-top:10px } </style> </head> <body> <h4>请输入公文标题:</h4> <form action="" method="post"> <div><input type="text" class="form-control" id="title"></div> <h4>请在下方书写正文:</h4> <div> <textarea id="doc" rows="20" cols="40"></textarea> </div> <div class="btnbag"> <input type="submit" class="btn" value="提交" onclick="submit()"> </div> </form> <% if(request.getParameter("result")!=null&&request.getParameter("result").equals("yes")) { %> <script> alert("提交成功!"); window.location="main.jsp"; </script> <%}%> </body> <script type="text/javascript"> function submit() { var text=$("#doc").val(); var user=GetQueryString("user"); var title=$("#title").val(); if(text==""||title=="") { alert("包含空内容!请填写完整!"); } } </script> </html>
package writedoc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class WritedBUtil { public static final String connectionURL="jdbc:mysql://localhost:3306/big-text?useUnicode=true&characterEncoding=GB18030&useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true"; public static final String username="root"; public static final String psw="123456"; static Connection connection; static ResultSet rSet; static PreparedStatement sql; public static Connection getConnection() { try { Class.forName("com.mysql.cj.jdbc.Driver"); System.out.println("数据库连接成功"); return DriverManager.getConnection(connectionURL, username, psw); } catch (Exception e) { // TODO: handle exception System.out.println("数据库连接失败"); e.printStackTrace(); } return null; } //数据库连接 public static boolean add(String title, String doc, int status,int result ,int delete, String receiver) //数据库的增添 { try { connection=getConnection(); sql =connection.prepareStatement("insert into new_table (title,doc,status,result,delete,receiver) values(\'"+title+"\',\'"+doc+"\',\'"+result+"\',\'"+delete+"\',\'"+receiver+"\')"); sql.executeUpdate();//执行语句 // System.out.println(sql); } catch (SQLException e) { // TODO 自动生成的 catch e.printStackTrace(); } return false; } public static boolean search(int x)//查 { try { connection=getConnection(); sql=connection.prepareStatement("select * from new_table where id="+x); System.out.println(sql); rSet=sql.executeQuery(); rSet.next(); System.out.println(rSet.getString(1)+" "+rSet.getString(2)+" "+rSet.getString(3)+" "+rSet.getString(4)); } catch (Exception e) { // TODO: handle exception } return false; } }
package writedoc; import java.io.IOException; 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 domain.Enter; /** * Servlet implementation class WriteServlet */ @WebServlet("/WriteServlet") public class WriteServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String title=request.getParameter("title"); String doc=request.getParameter("doc"); int status=2; int result=0; int delete=0; String receiver="办公室"; boolean a= WritedBUtil.add(title, doc, status, result, delete, receiver); if(a==true) { request.getRequestDispatcher("writedoc.jsp?result=yes").forward(request,response); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
二、存在的问题:一些流程的操作感觉还不太清楚,web用的还不是很熟悉。