关于开学考试
本次开学考试与上学期期末的题差不多,甚至更简单,主要考察的是增删改查的内容,在开学考试的时候,我完成了一半的内容,还剩下栏目管理员的内容没写,主要是因为栏目管理员的功能复杂,我没办法在三小时内完成全部内容,而其它身份的功能我也没有做得很好,比如客户的身份添加没有完成,并且管理员的所有功能我都忘了加按钮导致无法进行下一步,成员登录页面我也没有做得很好,比如在某些成员登录的时候会出现登录失败的信息,但还是能正常登录进去,本次开学考试结束我认清了自己的真实水平,在将来的学习上我将根据自己的不足进行改进。
以下是一些重要代码的展示:
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 charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="panduan.jsp" method="get">
<table align="center" border="1" width="500">
<tr align="center">
<td>河北省环保监测中心网络新闻发布系统</td>
                            </tr>
<tr align="center">
                       <td colspan="2">
账号:<input type="text" value="" name="hao" />
                       </td>
              </tr>
<tr align="center">
                       <td colspan="2">
密码:<input type="text" value="" name="mima" />
                       </td>
              </tr>
<tr align="center">
                       <td colspan="2">
身份:<select name="shenfen">	
				   <option value="1">新闻撰稿人</option>	
				   <option value="2">普通用户</option>
				   <option value="3">新闻栏目管理员</option>
				   <option value="4">系统管理</option>
				</select> <br />
                       </td>
              </tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="确定" />
</td>
              </tr>      
       
</table>
</form>
<form action="zhuce.jsp" method="get">
  <input type="submit" value="注册" />
</form>
</body>
</html>
2.登录判断:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>大</title>
</head>
<body>
 <%   String a1 = request.getParameter("hao");
 String a2 = request.getParameter("mima");
 String a3 = request.getParameter("shenfen");
 String a4="1";
        try {  
            Class.forName("com.mysql.jdbc.Driver");  //驱动程序名
            String url = "jdbc:mysql://localhost:3306/student"; //数据库名
            String username = "localhost";  //数据库用户名
            String password = "123456";  //数据库用户密码
            Connection conn = DriverManager.getConnection(url, username, password);  //连接状态
            if(conn != null){  
                
                out.print("<br />");            
                Statement stmt = null;  
                ResultSet rs = null;  
                String sql = "SELECT *FROM denglu;";
                
                stmt = conn.createStatement();  
                rs = stmt.executeQuery(sql);  
                while (rs.next()) {  
                	if(rs.getString("shenfen").equals("1"))
                	{if(rs.getString("zhanghao").equals(a1)&&rs.getString("mima").equals(a2))
                	{ 
                	%>
                	<form action="1.jsp" method="get">
                	
                	<input type="submit" value="登录成功" />
                	 </form>
                	 <% break;}  
                	else{%>
                	<form action="denglu.jsp" method="get">
                	<input type="submit" value="登录失败" />
                	 </form>
                	 <%} }
                	else if(rs.getString("shenfen").equals("2"))
                {if(rs.getString("zhanghao").equals(a1)&&rs.getString("mima").equals(a2))
            	{ 
            	%>
            	<form action="2.jsp" method="get">
            	
            	<input type="submit" value="登录成功" />
            	 </form>
            	 <% break;}  
            	else{%>
            	<form action="denglu.jsp" method="get">
            	<input type="submit" value="登录失败" />
            	 </form>
            	 <%} }
                	else if(rs.getString("shenfen").equals("3"))
                	{if(rs.getString("zhanghao").equals(a1)&&rs.getString("mima").equals(a2))
                	{ 
                    	%>
                    	<form action="3.jsp" method="get">
                    	
                    	<input type="submit" value="登录成功" />
                    	 </form>
                    	 <% break;}  
                    	else{%>
                    	<form action="denglu.jsp" method="get">
                    	<input type="submit" value="登录失败" />
                    	 </form>
                    	 <%} 
                		
                	}
                	else if(rs.getString("shenfen").equals("4"))
                	{if(rs.getString("zhanghao").equals(a1)&&rs.getString("mima").equals(a2))
                	{ 
                    	%>
                    	<form action="4.jsp" method="get">
                    	
                    	<input type="submit" value="登录成功" />
                    	 </form>
                    	 <% break;}  
                    	else{%>
                    	<form action="denglu.jsp" method="get">
                    	<input type="submit" value="登录失败" />
                    	 </form>
                    	 <%} }
                	
                }
            
            }
            
            else{  
             
            }  
        }catch (Exception e) {    
      
        }  
%> 
</body>
</html>
3.增删改查:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="1.jsp" method="get">
<%!
    public static final String DBDRIVER="com.mysql.cj.jdbc.Driver";
    public static final String DBURL="jdbc:mysql://localhost:3306/student?&useSSL=false&serverTimezone=UTC";
    public static final String DBUSER="root";
    public static final String DBPASS="123456";
%>
<%
 String a1=request.getParameter("1");
String a2=request.getParameter("2");
String a3=request.getParameter("3");
String a4=request.getParameter("4");
String a5=request.getParameter("5");
    Connection conn=null;
    try{
        Class.forName(DBDRIVER);
        conn= DriverManager.getConnection(DBURL,DBUSER,DBPASS);
        request.setCharacterEncoding("utf-8");
        Statement stmt = conn.createStatement();
        String sql_insert="insert into xinwen(biaoti,guanjianzi,zhuangaoren,lanmu,shijian,zhuangtai,pinglun,yijian) values ('"+a1+"','"+a2+"','"+a3+"','"+a4+"','"+a5+"','nopass',null,null)";
       
        stmt.executeUpdate(sql_insert);    
        
    }
catch(Exception e){
    out.println(e);
}
%> 
   <input type="submit" value="确认" />
        </form>   
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<head>"
<title>通过JSP打开数据表</title>
</head>
<body>
<form action="1.jsp" method="get">
 <%  
        try {  
            Class.forName("com.mysql.jdbc.Driver");  //驱动程序名
            String url = "jdbc:mysql://localhost:3306/student"; //数据库名
            String username = "localhost";  //数据库用户名
            String password = "123456";  //数据库用户密码
            Connection conn = DriverManager.getConnection(url, username, password);  //连接状态
            if(conn != null){  
                
                out.print("<br />");            
                Statement stmt = null;  
                ResultSet rs = null;  
                String sql = "SELECT *FROM xinwen;";  //查询语句
                stmt = conn.createStatement();  
                rs = stmt.executeQuery(sql);
                out.print("新闻                    意见");
                out.print("<br />");
                while (rs.next()) {  
                	
                	{ out.println(rs.getString("biaoti")+"      "+rs.getString("yijian")); 
                 out.print("<br />"); }
                  
            }  
            }
            else{  
                out.print("连接失败!");  
            }  
        }catch (Exception e) {        
            out.print("数据库连接异常!");  
        }  
%>   
<input type="submit" value="确认" />
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="1.jsp" method="get">
<%!
    public static final String DBDRIVER="com.mysql.cj.jdbc.Driver";
    public static final String DBURL="jdbc:mysql://localhost:3306/student?&useSSL=false&serverTimezone=UTC";
    public static final String DBUSER="root";
    public static final String DBPASS="123456";
%>
<%
 String a1=request.getParameter("1");
String a2=request.getParameter("2");
String a3=request.getParameter("3");
String a4=request.getParameter("4");
String a5=request.getParameter("5");
String a6=request.getParameter("6");
    Connection conn=null;
    try{
        Class.forName(DBDRIVER);
        conn= DriverManager.getConnection(DBURL,DBUSER,DBPASS);
        request.setCharacterEncoding("utf-8");
        Statement stmt = conn.createStatement();
        String sql="update xinwen set zhuangaoren='"+a3+"' where biaoti="+a6;
        stmt.executeUpdate(sql);
        sql="update xinwen set guanjianzi='"+a2+"' where biaoti="+a6;
        stmt.executeUpdate(sql);
        sql="update xinwen set lanmu='"+a4+"' where biaoti="+a6;
        stmt.executeUpdate(sql);
        sql="update xinwen set shijian='"+a5+"' where biaoti="+a6;
        stmt.executeUpdate(sql);
        sql="update xinwen set biaoti='"+a1+"' where biaoti="+a6;
        stmt.executeUpdate(sql);
        
    }
catch(Exception e){
    out.println(e);
}
%> 
   <input type="submit" value="确认" />
        </form>   
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<head>"
<title>通过JSP打开数据表</title>
</head>
<body>
<form action="1.jsp" method="get">
 <%   String a1 = request.getParameter("1");
 String a2 = request.getParameter("2");
        try {  
            Class.forName("com.mysql.jdbc.Driver");  //驱动程序名
            String url = "jdbc:mysql://localhost:3306/student"; //数据库名
            String username = "localhost";  //数据库用户名
            String password = "123456";  //数据库用户密码
            Connection conn = DriverManager.getConnection(url, username, password);  //连接状态
            if(conn != null){  
                
                out.print("<br />");            
                Statement stmt = null;  
                ResultSet rs = null;  
                String sql = "SELECT *FROM xinwen;";  //查询语句
                stmt = conn.createStatement();  
                rs = stmt.executeQuery(sql);  
               
                out.print("查询结果:");  
                out.print("<br />");  
                out.println("标题          关键字       撰写人          栏目           日期        状态       评论");  
                out.print("<br />");  
                while (rs.next()) {  
                	if(rs.getString("lanmu").equals(a1)||rs.getString("shijian").equals(a2))
                	{ out.println(rs.getString("biaoti")+"      "+rs.getString("guanjianzi")+"    "+rs.getString("zhuanxieren")+"    "+rs.getString("lanmu")+"    "+rs.getString("shijian")+"    "+rs.getString("zhuangtai")+"    "+rs.getString("pinglun")); 
                 out.print("<br />"); }  //将查询结果输出  
                  
            }  
            }
            else{  
                out.print("连接失败!");  
            }  
        }catch (Exception e) {        
            out.print("数据库连接异常!");  
        }  
%>   
<input type="submit" value="确认" />
</form>
</body>
</html>
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号