其他分享
首页 > 其他分享> > JSP_Homework_10_0518

JSP_Homework_10_0518

作者:互联网

1.实现 删除 回复邮件
2.实现阅读邮件功能:在main.jsp中点击任意邮件的标题,进入到detail.jsp显示邮件详情,包括发件人,主题,内容,时间。同时需要把邮件状态修改为已读。

 

大概就是在上次作业的基础上加了增删改

使用技术 SSM框架

..

 

controller层

package com.cotomi.controller;

import com.cotomi.entity.Email;
import com.cotomi.entity.Users;
import com.cotomi.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @ClassName EmailController
 * @Date 2022/5/11 22:07
 * @Author 音无彩名
 * @Description TODO
 */
@Controller
@RequestMapping("/email")
public class EmailController {
    @Autowired
    EmailService emailService;

    @RequestMapping("/main")
    public String main(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        Users users = (Users) session.getAttribute("user");
        List<Email> allEmail = emailService.getAllEmailByFromAndTo(users.getuUsername());
        request.setAttribute("allEmail", allEmail);
        return "main";
    }

    @RequestMapping("/detail")
    public String detail(HttpServletRequest request){
        String eid = request.getParameter("eid");
        emailService.updateStatusByEid(eid);
        Email email = emailService.getEmailByEid(eid);
        request.setAttribute("email", email);
        return "detail";
    }

    @RequestMapping("delete")
    public String delete(@RequestParam("eid")
                         String eid, HttpServletRequest request){
        if (emailService.deleteEmailByEid(eid) == 1){
            return "redirect:/email/main";
        }else {
            request.setAttribute("msg","删除异常");
            return "error";
        }
    }

    @RequestMapping("reply")
    public String reply(
            @RequestParam("eFrom")
            String eFrom, HttpServletRequest request){
        request.setAttribute("eTo", eFrom);
        return "addEmail";
    }

    @RequestMapping("addEmail")
    public String addEmail(Email email){
        email.seteStatus("未读");
        email.seteDatetime(new Date());
        emailService.addEmail(email);
        return "redirect:/email/main";
    }
}

 

package com.cotomi.controller;

import com.cotomi.entity.Users;
import com.cotomi.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @ClassName UsersController
 * @Date 2022/5/11 21:08
 * @Author 音无彩名
 * @Description TODO
 */
@Controller
@RequestMapping("/users")
public class UsersController {
    @Autowired
    UsersService usersService;

    @RequestMapping("/inlogin")
    public String inLogin(){
        return "inLogin";
    }

    @RequestMapping("/main")
    public String main(){
        return "main";
    }

    @RequestMapping("/login")
    public String login(String username, String password, HttpServletRequest request){
        HttpSession session = request.getSession();
        Users user = usersService.login(username, password);
        if (user == null){
            request.setAttribute("msg","用户名或密码错误");
            return "inLogin";
        }
        session.setAttribute("user",user);
        return "redirect:/email/main";
    }

    @RequestMapping("/inregister")
    public String inRegister(){
        return "inRegister";
    }

    @RequestMapping("/register")
    public String register(String username, String password, HttpServletRequest request){
        int success = usersService.register(new Users(username, password));
        if (success == 1){
            request.setAttribute("msg", "注册成功,请登录");
            return "inLogin";
        }else {
            request.setAttribute("msg", "注册失败,未知异常");
            return "inRegister";
        }
    }
}

 

interceptor拦截器

package com.cotomi.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @ClassName LoginInterceptor
 * @Date 2022/5/11 21:17
 * @Author 音无彩名
 * @Description TODO
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession(false);
        if (session == null || session.getAttribute("user") == null){
            request.setAttribute("msg","请先登录哦");
            request.getRequestDispatcher("/WEB-INF/jsp/inLogin.jsp").forward(request,response);
            return false;
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}

 

service层

package com.cotomi.service;

import com.cotomi.entity.Email;

import java.util.List;

/**
 * @ClassName EmailMapper
 * @Date 2022/5/11 19:42
 * @Author 音无彩名
 * @Description TODO
 */
public interface EmailService{
    List<Email> getAllEmailByFromUsername(String fromUsername);
    List<Email> getAllEmailByToUsername(String toUsername);
    List<Email> getAllEmailByFromAndTo(String username);
    Email getEmailByEid(String eid);
    int deleteEmailByEid(String eid);
    int addEmail(Email email);
    int updateStatusByEid(String eid);
}

 

package com.cotomi.service;

import com.cotomi.entity.Users;
import org.apache.ibatis.annotations.Param;

/**
 * @ClassName UsersServiceImpl
 * @Date 2022/5/11 18:12
 * @Author 音无彩名
 * @Description TODO
 */
public interface UsersService {
    Users login(String username, String password);

    int register(Users users);
}

 

package com.cotomi.service.impl;

import com.cotomi.entity.Email;
import com.cotomi.mapper.EmailMapper;
import com.cotomi.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName EmailServiceImpl
 * @Date 2022/5/11 19:46
 * @Author 音无彩名
 * @Description TODO
 */
@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    EmailMapper emailMapper;

    @Override
    public List<Email> getAllEmailByFromUsername(String fromUsername) {
        return emailMapper.getAllEmailByFromUsername(fromUsername);
    }

    @Override
    public List<Email> getAllEmailByToUsername(String toUsername) {
        return emailMapper.getAllEmailByToUsername(toUsername);
    }

    @Override
    public List<Email> getAllEmailByFromAndTo(String username) {
        List<Email> username1 = emailMapper.getAllEmailByToUsername(username);
        List<Email> username2 = emailMapper.getAllEmailByFromUsername(username);
        username1.addAll(username2);
        return username1;
    }

    @Override
    public Email getEmailByEid(String eid) {
        Email email = emailMapper.getEmailByEid(eid);
        return email;
    }

    @Override
    public int deleteEmailByEid(String eid) {
        int i = emailMapper.deleteEmailByEid(eid);
        return i;
    }

    @Override
    public int addEmail(Email email) {
        int i = emailMapper.addEmail(email);
        return i;
    }

    @Override
    public int updateStatusByEid(String eid) {
        int i = emailMapper.updateStatusByEid(eid);
        return i;
    }
}

 

package com.cotomi.service.impl;

import com.cotomi.entity.Users;
import com.cotomi.mapper.UsersMapper;
import com.cotomi.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName UsersServiceImpl
 * @Date 2022/5/11 18:11
 * @Author 音无彩名
 * @Description TODO
 */
@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    UsersMapper usersMapper;


    @Override
    public Users login(String username, String password) {
        return usersMapper.login(username, password);
    }

    @Override
    public int register(Users users) {
        return usersMapper.register(users);
    }
}

 

mapper层

package com.cotomi.mapper;

import com.cotomi.entity.Email;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @ClassName EmailMapper
 * @Date 2022/5/11 17:44
 * @Author 音无彩名
 * @Description TODO
 */
public interface EmailMapper {
/**
 * @MethodName: getAllEmailByFromUsername
 * @Description: 通过发件人用户名获取该用户发送的所有邮件
 * @Author: 音无彩名
 * @Date: 2022/5/11 19:15
 * @param fromUsername: 发件人姓名
 * @return java.util.List<com.cotomi.entity.Email>
 */
    List<Email> getAllEmailByFromUsername(
            @Param("fromUsername")
            String fromUsername);

    /**
     * @MethodName: getAllEmailByToUsername
     * @Description: 通过收件人用户名字获取该用户发送的所有邮件
     * @Author: 音无彩名
     * @Date: 2022/5/11 19:22
     * @param toUsername: 收件人姓名
     * @return java.util.List<com.cotomi.entity.Email>
     */
    List<Email> getAllEmailByToUsername(
            @Param("toUsername")
            String toUsername);
    /**
     * @MethodName: getEmailByEid
     * @Description: 通过邮件id获取该邮件详细信息
     * @Author: 音无彩名
     * @Date: 2022/5/21 22:54
     * @param eid: 邮件id
     * @return com.cotomi.entity.Email
     */
    Email getEmailByEid(
            @Param("eid")
            String eid);
    /**
     * @MethodName: deleteEmailByEid
     * @Description: 通过邮件id删除该邮件
     * @Author: 音无彩名
     * @Date: 2022/5/21 23:46
     * @param eid: 邮件id
     * @return int
     */
    int deleteEmailByEid(
            @Param("eid")
            String eid);
    /**
     * @MethodName: addEmail
     * @Description: 向邮件数据添加一个新的邮件
     * @Author: 音无彩名
     * @Date: 2022/5/22 1:17
     * @param email: 邮件实体类
     * @return int 成功条数
     */
    int addEmail(Email email);

/**
 * @MethodName: updateStatusByEid
 * @Description: 通过邮件id修改邮件状态
 * @Author: 音无彩名
 * @Date: 2022/5/22 1:44
 * @param eid: 邮件id
 * @return int
 */
    int updateStatusByEid(
            @Param("eid")
            String eid);
}

 

package com.cotomi.mapper;

import com.cotomi.entity.Users;
import org.apache.ibatis.annotations.Param;

/**
 * @ClassName UsersMapper
 * @Date 2022/5/11 17:44
 * @Author 音无彩名
 * @Description TODO
 */
public interface UsersMapper {
    Users login(
            @Param("username")
            String username,
            @Param("password")
            String password);

    int register(
            @Param("users")
            Users users);
}

 

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cotomi.mapper.EmailMapper">

<!--
  private Integer eid;
  private String eFrom;
  private String eTo;
  private String eTitle;
  private String eContent;
  private java.sql.Timestamp eDatetime;
  private String eStatus;-->
    <resultMap id="emailMapper" type="email">
        <id property="eid" column="eid"></id>
        <result property="eFrom" column="e_from"></result>
        <result property="eTo" column="e_to"></result>
        <result property="eTitle" column="e_title"></result>
        <result property="eContent" column="e_content"></result>
        <result property="eDatetime" column="e_datetime"></result>
        <result property="eStatus" column="e_status"></result>
    </resultMap>
    <sql id="allColumn">
        eid, e_from, e_to, e_title, e_content, e_datetime, e_status
    </sql>
    <sql id="allColumnNoId">
        e_from, e_to, e_title, e_content, e_datetime, e_status
    </sql>
<!--    List<Email> getAllEmailByFromUsername(
            @Param("fromUsername")
            String fromUsername);-->
    <select id="getAllEmailByFromUsername" parameterType="string" resultMap="emailMapper">
        select <include refid="allColumn"></include> from email where e_from = #{fromUsername}
    </select>

<!--        List<Email> getAllEmailByToUsername(
            @Param("toUsername")
            String toUsername);-->
    <select id="getAllEmailByToUsername" parameterType="string" resultMap="emailMapper">
        select <include refid="allColumn"></include> from email where e_to = #{toUsername}
    </select>

<!--      Email getEmailByEid(
            @Param("eid")
            String eid);-->
    <select id="getEmailByEid" parameterType="string" resultMap="emailMapper">
        select <include refid="allColumn"></include> from email where eid = #{eid}
    </select>
<!--        int deleteEmailByEid(
            @Param("eid")
            String eid);-->
    <delete id="deleteEmailByEid" parameterType="string">
        delete from email where eid = #{eid}
    </delete>
<!--    int addEmail(Email email);
  private Integer eid;
  private String eFrom;
  private String eTo;
  private String eTitle;
  private String eContent;
  private Date eDatetime;
  private String eStatus;
-->
    <insert id="addEmail" parameterType="email">
        insert into email (<include refid="allColumnNoId"></include>) values (#{eFrom}, #{eTo},#{eTitle},#{eContent},#{eDatetime},#{eStatus})
    </insert>
<!--        int updateStatusByEid(
            @Param("eid")
            String eid);-->
    <update id="updateStatusByEid" parameterType="string">
        update email set e_status = '已读' where eid = #{eid}
    </update>
</mapper>

 

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cotomi.mapper.UsersMapper">
<!--
  private Integer uid;
  private String uUsername;
  private String uPassword;
-->
    <resultMap id="usersMapper" type="users">
        <id property="uid" column="uid"></id>
        <result property="uUsername" column="u_username"></result>
        <result property="uPassword" column="u_password"></result>
    </resultMap>

    <sql id="allColumn">
        uid, u_username, u_password
    </sql>
    <sql id="allColumnNoId">
        u_username, u_password
    </sql>
<!--        Users login(
            @Param("username")
            String username,
            @Param("password")
            String password);-->
    <select id="login" resultMap="usersMapper">
        select <include refid="allColumn"></include> from users where u_username = #{username} and u_password = #{password}
    </select>

<!--        int register(
            @Param("users")
            Users users);-->
    <insert id="register">
        insert into users (<include refid="allColumnNoId"></include>) values (#{users.uUsername},#{users.uPassword})
    </insert>
</mapper>

 

实体类

 

package com.cotomi.entity;


import java.util.Date;


public class Email {

  private Integer eid;
  private String eFrom;
  private String eTo;
  private String eTitle;
  private String eContent;
  private Date eDatetime;
  private String eStatus;


  public Email() {
  }

  public Email(Integer eid, String eFrom, String eTo, String eTitle, String eContent, Date eDatetime, String eStatus) {
    this.eid = eid;
    this.eFrom = eFrom;
    this.eTo = eTo;
    this.eTitle = eTitle;
    this.eContent = eContent;
    this.eDatetime = eDatetime;
    this.eStatus = eStatus;
  }

  public Email(String eFrom, String eTo, String eTitle, String eContent, Date eDatetime, String eStatus) {
    this.eFrom = eFrom;
    this.eTo = eTo;
    this.eTitle = eTitle;
    this.eContent = eContent;
    this.eDatetime = eDatetime;
    this.eStatus = eStatus;
  }

  public Integer getEid() {
    return eid;
  }

  public void setEid(Integer eid) {
    this.eid = eid;
  }

  public String geteFrom() {
    return eFrom;
  }

  public void seteFrom(String eFrom) {
    this.eFrom = eFrom;
  }

  public String geteTo() {
    return eTo;
  }

  public void seteTo(String eTo) {
    this.eTo = eTo;
  }

  public String geteTitle() {
    return eTitle;
  }

  public void seteTitle(String eTitle) {
    this.eTitle = eTitle;
  }

  public String geteContent() {
    return eContent;
  }

  public void seteContent(String eContent) {
    this.eContent = eContent;
  }

  public Date geteDatetime() {
    return eDatetime;
  }

  public void seteDatetime(Date eDatetime) {
    this.eDatetime = eDatetime;
  }

  public String geteStatus() {
    return eStatus;
  }

  public void seteStatus(String eStatus) {
    this.eStatus = eStatus;
  }

  @Override
  public String toString() {
    return "Email{" +
            "eid=" + eid +
            ", eFrom='" + eFrom + '\'' +
            ", eTo='" + eTo + '\'' +
            ", eTitle='" + eTitle + '\'' +
            ", eContent='" + eContent + '\'' +
            ", eDatetime=" + eDatetime +
            ", eStatus='" + eStatus + '\'' +
            '}';
  }
}

 

package com.cotomi.entity;


public class Users {

  private Integer uid;
  private String uUsername;
  private String uPassword;

  public Users() {
  }

  public Users(Integer uid, String uUsername, String uPassword) {
    this.uid = uid;
    this.uUsername = uUsername;
    this.uPassword = uPassword;
  }

  public Users(String uUsername, String uPassword) {
    this.uUsername = uUsername;
    this.uPassword = uPassword;
  }

  public Integer getUid() {
    return uid;
  }

  public void setUid(Integer uid) {
    this.uid = uid;
  }

  public String getuUsername() {
    return uUsername;
  }

  public void setuUsername(String uUsername) {
    this.uUsername = uUsername;
  }

  public String getuPassword() {
    return uPassword;
  }

  public void setuPassword(String uPassword) {
    this.uPassword = uPassword;
  }

  @Override
  public String toString() {
    return "Users{" +
            "uid=" + uid +
            ", uUsername='" + uUsername + '\'' +
            ", uPassword='" + uPassword + '\'' +
            '}';
  }
}

 

spring与springMVC配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
        <property name="typeAliasesPackage" value="com.cotomi.entity"></property>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.cotomi.mapper"></property>
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
    <context:component-scan base-package="com.cotomi.service.impl"></context:component-scan>
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <tx:advice id="myadvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*select*" read-only="true"/>
            <tx:method name="*find*" read-only="true"/>
            <tx:method name="*search*" read-only="true"/>
            <tx:method name="*get*" read-only="true"/>

            <tx:method name="*insert*" propagation="REQUIRED"/>
            <tx:method name="*add*" propagation="REQUIRED"/>
            <tx:method name="*save*" propagation="REQUIRED"/>
            <tx:method name="*register*" propagation="REQUIRED"/>

            <tx:method name="*update*" propagation="REQUIRED"/>
            <tx:method name="*change*" propagation="REQUIRED"/>
            <tx:method name="*modify*" propagation="REQUIRED"/>
            <tx:method name="*set*" propagation="REQUIRED"/>

            <tx:method name="*delete*" propagation="REQUIRED"/>
            <tx:method name="*drop*" propagation="REQUIRED"/>
            <tx:method name="*remove*" propagation="REQUIRED"/>
            <tx:method name="*clear*" propagation="REQUIRED"/>

            <tx:method name="*" propagation="SUPPORTS"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="mycut" expression="execution(* com.cotomi.service.impl.*.*(..))"/>
        <aop:advisor advice-ref="myadvice" pointcut-ref="mycut"></aop:advisor>
    </aop:config>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <context:component-scan base-package="com.cotomi.controller"></context:component-scan>
    <mvc:annotation-driven></mvc:annotation-driven>
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/users/inlogin"/>
            <mvc:exclude-mapping path="/users/login"/>
            <mvc:exclude-mapping path="/users/register"/>
            <mvc:exclude-mapping path="/users/inregister"/>
            <bean class="com.cotomi.interceptor.LoginInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>
</beans>

 

jdbc:

jdbc.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
jdbc.username=root
jdbc.password=root

 

SqlMapConfig

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
</configuration>

 

jsp界面:

<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/22
  Time: 0:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>addEmail</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/email/addEmail">
    <tr>
        <td>发件人</td>
        <td><input type="text" name="eFrom" value="${sessionScope.user.uUsername}"></td>
    </tr>
    <tr>
        <td>收件人</td>
        <td><input type="text" name="eTo" value="${requestScope.eTo}"></td>
    </tr>
    <tr>
        <td>标题</td>
        <td><input type="text" name="eTitle"></td>
    </tr>
    <tr>
        <td>内容</td>
        <td><input type="text" name="eContent"></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="发送">
        </td>
    </tr>
</form>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/21
  Time: 22:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h2>邮件详细信息</h2>
<h2>欢迎你 ${sessionScope.user.uUsername} </h2>
<table border="1px" cellspacing="0px" cellpadding="30px">
    <tr>
        <th>邮件id</th>
        <th>发件人</th>
        <th>收件人</th>
        <th>标题</th>
        <th>内容</th>
        <th>创建日期</th>
        <th>邮件状态</th>
    </tr>
    <tr>
        <td>${email.eid}</td>
        <td>${email.eFrom}</td>
        <td>${email.eTo}</td>
        <td>${email.eTitle}</td>
        <td>${email.eContent}</td>
        <td><fmt:formatDate value="${email.eDatetime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
        <td>${email.eStatus}</td>
    </tr>
</table>
<input type="button" value="返回" onclick="history.back()"><br><br>
<form action="${pageContext.request.contextPath}/email/delete" method="get">
    <input type="hidden" name="eid" value="${email.eid}">
    <input type="submit" value="删除该邮件"><br><br>
</form>
<form action="${pageContext.request.contextPath}/email/reply" method="get">
    <input type="hidden" name="eFrom" value="${email.eFrom}">
    <input type="submit" value="回复该邮件"><br><br>
</form>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/22
  Time: 0:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h2>出错了</h2>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/11
  Time: 17:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/users/login" method="post">
    用户名:<input type="text" name="username"><br>
    密码:<input type="password" name="password"><br>
    <input type="submit" value="登录">
</form>
${msg}
<hr>
<a href="${pageContext.request.contextPath}/users/inregister">注册界面</a>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/11
  Time: 17:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/users/register" method="post">
    <h2>注册界面</h2>
    用户名<input type="text" name="username"><br>
    <td>密码<input type="password" name="password"><br>
    <td colspan="3"><input type="submit" value="注册">
</form>
<a href="${pageContext.request.contextPath}/users/inlogin">登录界面</a>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/11
  Time: 19:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>主界面</title>
</head>
<body>
<h2>登录成功</h2>
<h2>欢迎你 ${sessionScope.user.uUsername} </h2>
${requestScope.msg}
<table border="1px" cellspacing="0px" cellpadding="30px">
    <tr>
        <th>邮件id</th>
        <th>标题</th>
        <th>创建日期</th>
        <th>邮件状态</th>
    </tr>
    <c:forEach items="${requestScope.allEmail}" var="email" varStatus="count">
        <tr>
            <td>${email.eid}</td>f
            <td><a href="${pageContext.request.contextPath}/email/detail?eid=${email.eid}">${email.eTitle}</a></td>
            <td><fmt:formatDate value="${email.eDatetime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
            <td>${email.eStatus}</td>
        </tr>
    </c:forEach>
</table>
<input type="button" value="刷新" onclick="location.reload()">
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/5/11
  Time: 18:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>开始</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/users/inlogin">一切从这里开始</a>
</body>
</html>

 

web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
<!--
    private String encoding;
    private boolean forceRequestEncoding;
    private boolean forceResponseEncoding;
-->
    <filter>
        <filter-name>encode</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceRequestEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>forceResponseEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encode</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext_*.xml</param-value>
    </context-param>
</web-app>

 

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.cotomi</groupId>
  <artifactId>test0511</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>



  <!-- 集中定义依赖版本号 -->
  <properties>
    <!--    单元测试的依赖-->
    <junit.version>4.12</junit.version>
    <!--    spring相关依赖-->
    <spring.version>5.2.5.RELEASE</spring.version>
    <!--    mybatis的相关依赖-->
    <mybatis.version>3.5.1</mybatis.version>
    <!--    mybatis与spring整合的依赖-->
    <mybatis.spring.version>1.3.1</mybatis.spring.version>
    <!--    mybatis的分页插件的依赖 前端若是vue等框架则用不到,若前端是jsp则一定会用到-->
    <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
    <!--    mysql的依赖-->
    <mysql.version>8.0.28</mysql.version>
    <!--    slf4j日志依赖-->
    <slf4j.version>1.6.4</slf4j.version>
    <!--    阿里巴巴德鲁伊数据库连接池-->
    <druid.version>1.1.12</druid.version>
    <!--    分页插件的依赖-->
    <pagehelper.version>5.1.2</pagehelper.version>
    <!--    jstl的依赖(jsp的标准标签库)-->
    <jstl.version>1.2</jstl.version>
    <!--    servlet依赖-->
    <servlet-api.version>3.0.1</servlet-api.version>
    <!--    jsp的依赖-->
    <jsp-api.version>2.0</jsp-api.version>
    <!--    Jackson的依赖,springMVC框架默认进行JSON转换的依赖工具-->
    <jackson.version>2.9.6</jackson.version>
  </properties>

  <dependencies>
    <!-- spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jms</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>5.2.5.RELEASE</version>
    </dependency>
    <!-- Mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>${mybatis.version}</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>${mybatis.spring.version}</version>
    </dependency>
    <dependency>
      <groupId>com.github.miemiedev</groupId>
      <artifactId>mybatis-paginator</artifactId>
      <version>${mybatis.paginator.version}</version>
    </dependency>
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>${pagehelper.version}</version>
    </dependency>
    <!-- MySql -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
    </dependency>
    <!-- 连接池 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>${druid.version}</version>
    </dependency>

    <!-- junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>com.bjpowernode.test</scope>
    </dependency>


    <!-- JSP相关 -->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>${jstl.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <scope>provided</scope>
      <version>${jsp-api.version}</version>
    </dependency>
    <!-- Jackson Json处理工具包 -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20140107</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
  </dependencies>

  <!-- 插件配置 -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
    <!--识别所有的配置文件-->
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>
  </build>

</project>

 

数据库创建语句:

CREATE TABLE `email` (
  `eid` int NOT NULL AUTO_INCREMENT,
  `e_from` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '发件人',
  `e_to` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '收件人',
  `e_title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '邮件标题',
  `e_content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '邮件内容',
  `e_datetime` datetime NOT NULL COMMENT '邮件发送时间',
  `e_status` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '邮件状态',
  PRIMARY KEY (`eid`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb3;
CREATE TABLE `users` (
  `uid` int NOT NULL AUTO_INCREMENT,
  `u_username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `u_password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3;

 

运行截图:

 

 

 

 

 

 

 

 

————————————————————————————————————————————————————————

——————————————————————————————————————————

 

 

 

 

..

 

 安

 

 

标签:10,return,String,0518,email,JSP,eid,import,public
来源: https://www.cnblogs.com/cotomi/p/16296802.html