zoukankan      html  css  js  c++  java
  • 第十周--邮件系统全套(第二版)

    package cn;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    
    
    
    
    
    public class MailDao {
    
    	/**
    	 * @param args
    	 */
    	 
    		   public List<Mail> getSelect(String recive){
    			 List<Mail> list=new ArrayList<Mail>();
    				Connection con=null;
    				PreparedStatement st=null;
    				ResultSet rst=null;
    				try{
    					con=JDBCUtils.getCon();
    					
    					String sql="select*from mail where recive=?";
    					st=con.prepareStatement(sql);
    					st.setString(1, recive);
    					
    					rst=st.executeQuery();
    					while(rst.next()){
    						Mail mm=new Mail();
    						mm.setIds(rst.getInt("ids"));
    						mm.setSender(rst.getString("sender"));
    						mm.setTitle(rst.getString("title"));
    						mm.setContent(rst.getString("content"));
    						mm.setRecive(rst.getString("recive"));
    						mm.setDate(rst.getString("date"));
    						mm.setState(rst.getInt("state"));
    						list.add(mm);
    					}
    					
    					return list;  
    					
    				}catch(Exception e){
    					throw new RuntimeException(e);
    				}
    			 finally{
    				 JDBCUtils.closeAll(rst, st, con);
    			 }
    		   }
    		   
    		   //添加
    	            public boolean insert(Mail mail){
    	            	Connection con=null;
    					Statement st=null;
    					ResultSet rst=null;
    	               try{
    	            	   con=JDBCUtils.getCon();
    	            	   
    	            	   st=con.createStatement();
    	            	   
    	            	
    	            	   
    	            	    int row=st.executeUpdate("insert into mail values('"+mail.getIds()+"','"+mail.getSender()+"','"+mail.getTitle()+"','"+mail.getContent()+"','"+mail.getRecive()+"','"+mail.getDate()+"','"+mail.getState()+"'"+")");
    	            	    
    	            	    if(row==1){
    	            	    	return true;
    	            	    }
    	            	   
    	               }catch(Exception e){
    						throw new RuntimeException(e);
    					}
    				 finally{
    					 JDBCUtils.closeAll(rst, st, con);
    				 }
    	            	return false;
    	            }
    	   //根据id查询内容                  
    	            public Mail getSelects(int ids){
    	   		
    	   				Connection con=null;
    	   				PreparedStatement st=null;
    	   				ResultSet rst=null;
    	   				try{
    	   					con=JDBCUtils.getCon();
    	   					
    	   					String sql="select*from mail where ids=? ";
    	   					
    	   					st=con.prepareStatement(sql);
    	   					
    	   					st.setInt(1, ids);
    	   				
    	   					rst=st.executeQuery();
    	   					
    	   					while(rst.next()){
    	   						Mail mm=new Mail();
    	   						mm.setIds(rst.getInt("ids"));
    	   						mm.setSender(rst.getString("sender"));
    	   						mm.setTitle(rst.getString("title"));
    	   						mm.setContent(rst.getString("content"));
    	   						mm.setRecive(rst.getString("recive"));
    	   						mm.setDate(rst.getString("date"));
    	   						mm.setState(rst.getInt("state"));
    	   						return mm;
    	   					}
    	   					
    	   					
    	   					
    	   				}catch(Exception e){
    	   					throw new RuntimeException(e);
    	   				}
    	   			 finally{
    	   				 JDBCUtils.closeAll(rst, st, con);
    	   			 }
    					return null;
    	   		   }
    	   		   
    	            
    	            
    	  //根据id改变已读 图标         
    	      public boolean getChange(int ids){
    	    	  Connection con=null;
     				PreparedStatement st=null;
     				ResultSet rst=null;
     				try{
     					con=JDBCUtils.getCon();
     					String sql="update mail set state=1 where ids=?";
     					st=con.prepareStatement(sql);
     					
     					st.setInt(1, ids);
     					
     					int row =st.executeUpdate();
     					if(row==1){
     						return true;
     					}
     				
     					
     				}catch(Exception e){
       					throw new RuntimeException(e);
       				}
       			 finally{
       				 JDBCUtils.closeAll(rst, st, con);
       			 }
    	    	  
    	    	  return false;
    	      }
    	            
    	            
    	            
    	            
    	            
    	//    删除根据id
    	       public boolean getDelete(int ids){
    	    	   Connection con=null;
    				PreparedStatement st=null;
    				ResultSet rst=null;
    	    	   
    				try{
     					con=JDBCUtils.getCon();
     					String sql="delete from mail where ids=?";
     					st=con.prepareStatement(sql);
     					
     					st.setInt(1, ids);
     					
     					int row =st.executeUpdate();
     					if(row==1){
     						return true;
     					}
     				
     					
     				}catch(Exception e){
       					throw new RuntimeException(e);
       				}
       			 finally{
       				 JDBCUtils.closeAll(rst, st, con);
       			 }
    	    	  
    	    	  return false;
    	      }
    	            
    	            
    	            
    	            
    	            
    	            
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		
    	}
    
    }
    

      

    package cn;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    
    
    public class UsDao {
               
    	
    	public boolean getLogin(String zzhh,String mima){
    		Connection con=null;
    		PreparedStatement st=null;
    		ResultSet rst=null;
    		
    		try{
    			con=JDBCUtils.getCon();
    			
    			
    			
    			String sql="select*from us where zzhh=? and mima=?";
    			
    			st=con.prepareStatement(sql);
    			st.setString(1, zzhh);
    			st.setString(2, mima);
    			
    			rst=st.executeQuery();
    			
    			if(rst.next()){
    				return true;
    			}
    			
    			
    			
    			
    			
    			
    		}catch(Exception e){
    			throw new RuntimeException(e);
    		}
    		finally{
    		   JDBCUtils.closeAll(rst, st, con);
    		}
    		
    		
    		return false;
    	}
    	
    	
    	
    	
    	
    	
    	
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    //          UsDao d=new UsDao();
    //          
    //         System.out.println(d.getLogin("Lisa","123456")); 
    		
    	}
    
    }
    

      

     
      <body>
       <form action="dologin.jsp" method="post">
                账号:<input type="text" name="username"> <br> <br>
                密码: <input type="text" name="password">    <br>  <br>
                <input type="submit" value="登录">
        </form>
      </body>
    </html>
    

      

    <body>
               <%
                 String username=request.getParameter("username");
                  session.setAttribute("username", username);
                  String password=request.getParameter("password");
                  UsDao d=new UsDao();
                  
                 if(d.getLogin(username, password)){
                    request.getRequestDispatcher("main.jsp").forward(request, response);
                  }else{
                  response.sendRedirect("login.jsp");
                  }
                %>
                
      </body>
    

      

    <body>
           <%
           String username=(String)session.getAttribute("username");
            %>
        <h3>发件人:<%=username %></h3>
              <form action="add2.jsp" method="post">
        send to:<input type="text" name="res"><br><br>     
             标题: <input type="text" name="title"><br><br>
             内容:  <input type="text" name="content"><br><br>
               
               <input type="submit" value="发送" >
              
              </form>
      </body>
    

      

    <body>
            
         <%
         request.setCharacterEncoding("utf-8");
         String username=(String)session.getAttribute("username");
         String title=request.getParameter("title");
         String content=request.getParameter("content");
         String res=request.getParameter("res");
               MailDao d=new MailDao();
                 Mail m=new Mail();
                 
           
               
              
              
                m.setSender(username);
                m.setTitle(title);
                m.setContent(conte
                m.setRecive(res);
                m.setDate("20200507");
                m.setState(0);
                d.insert(m);
    <body>
        <% 
     
         request.setCharacterEncoding("utf-8");
        int id=Integer.parseInt(request.getParameter("titles"));
        
        
         %>
         
        <%   
               MailDao dd=new MailDao();
               dd.getChange(id);
               Mail m=dd.getSelects(id);
          
            
             
         %>
              
       
       
        <br>
         来自于: <%=m.getSender() %>
         <br><br>
        标题:  <%=m.getTitle() %>
         <br><br>
        内容: <%=m.getContent() %>
        <br><br>
      时间:<%=m.getDate() %>
        <br><br>
      
      <a href="main.jsp">返回</a>
      
      
      
    
      </body>
    

      

    <body>
           
               <%
          String sds=request.getParameter("sds");
             session.setAttribute("key", sds);
          %>
    
    <form action="doreturn.jsp" method="post">
         收件人: <%=sds %>
         <br> <br>
         标 题: <input type="text" name="tt">
         <br> <br>
         内容: <input type="text" name="cc">
         <br> <br>
         <input type="submit" value="发送">
         <a href="main.jsp">返回</a>
         </form>
         
         
         
         
      </body>
    

      

     <body>
              <%
              request.setCharacterEncoding("utf-8");
              String username=(String)session.getAttribute("username");
                 String sds=(String)session.getAttribute("key");
                String tt=request.getParameter("tt");
                String cc=request.getParameter("cc");
                
                MailDao md=new MailDao();
                
                Mail mm=new Mail();
                
                mm.setSender(username);
                mm.setTitle(tt);
                mm.setContent(cc);
                mm.setRecive(sds);
                mm.setDate("20200801");
                mm.setState(0);
                
                md.insert(mm);
                
                request.getRequestDispatcher("return.jsp").forward(request,response);
                
                
               %>
              
      </body>
    

      

     <body>
              <%
              request.setCharacterEncoding("utf-8");
              String username=(String)session.getAttribute("username");
                 String sds=(String)session.getAttribute("key");
                String tt=request.getParameter("tt");
                String cc=request.getParameter("cc");
                
                MailDao md=new MailDao();
                
                Mail mm=new Mail();
                
                mm.setSender(username);
                mm.setTitle(tt);
                mm.setContent(cc);
                mm.setRecive(sds);
                mm.setDate("20200801");
                mm.setState(0);
                
                md.insert(mm);
                
                request.getRequestDispatcher("return.jsp").forward(request,response);
                
                
               %>
              
      </body>
    

      

    request.getRequestDispatcher("login.jsp").forward(request, response); %
  • 相关阅读:
    Java JMX 监管
    Spring Boot REST(一)核心接口
    JSR 规范目录
    【平衡树】宠物收养所 HNOI 2004
    【树型DP】叶子的颜色 OUROJ 1698
    【匈牙利匹配】无题II HDU2236
    【贪心】Communication System POJ 1018
    【贪心】Moving Tables POJ 1083
    Calling Extraterrestrial Intelligence Again POJ 1411
    【贪心】Allowance POJ 3040
  • 原文地址:https://www.cnblogs.com/gsfwxj1820/p/12859893.html
Copyright © 2011-2022 走看看