struts2-spring-mybatis增删查改demo

对struts2的 初步学习制作的增删查改项目

目录结构:

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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>

  <name>struts2-demo</name>
  <groupId>org.example</groupId>
  <artifactId>struts2-demo</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <java.version>1.8</java.version>
    <struts2.version>2.5</struts2.version>
    <springframework.version>5.2.0.RELEASE</springframework.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.13</version>
    </dependency>

    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.2.4</version>
    </dependency>

    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>${struts2.version}</version>
      <exclusions>
        <exclusion>
          <artifactId>asm</artifactId>
          <groupId>asm</groupId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-convention-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-spring-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-java8-support-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
    </dependency>

    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.0</version>
    </dependency>

    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.0</version>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-framework-bom</artifactId>
        <version>${springframework.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

entity层 Student:

package com.gja.entity;

public class Student {

    private Long id;
    private String name;
    private Integer age;

    public Student() {
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

dao层 StudentDao:

package com.gja.dao;

import com.gja.entity.Student;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository //@Repository用于标注数据访问组件,即DAO组件
public interface StudentDao {

    public Student findByName(String name);

    public void add(Student student);

    public void delete(long studentId);

    public void update(Student student);

    public List<Student> findAll();
}

service层 StudentService:

package com.gja.service;

import com.gja.entity.Student;

import java.util.List;

public interface StudentService {

    public Student getByName(String name);

    public void addStudent(Student student);

    public void deleteStudent(long studentId);

    public void updateStudent(Student student);

    public List<Student> findAll();
}

实现service接口 StudentServiceImpl:

package com.gja.service.impl;

import com.gja.dao.StudentDao;
import com.gja.entity.Student;
import com.gja.service.StudentService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service //@Service用于标注业务层组件
public class StudentServiceImpl implements StudentService {

    @Resource //@Resource主要做依赖注入的,从容器中自动获取bean,和@Autowired用法相似
    private StudentDao studentDao;

    public Student getByName(String name) {
        return studentDao.findByName(name);
    }

    public void addStudent(Student student) {
        studentDao.add(student);
    }

    public void deleteStudent(long studentId) {
        studentDao.delete(studentId);
    }

    public void updateStudent(Student student) {
        studentDao.update(student);
    }

    public List<Student> findAll() {
        return studentDao.findAll();
    }
}

action层 StudentAction:

package com.gja.action;

import com.gja.entity.Student;
import com.gja.service.StudentService;
import com.opensymphony.xwork2.ActionSupport;
import javax.annotation.Resource;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class StudentAction extends ActionSupport {

    private static Queue<String> queue = new ConcurrentLinkedQueue<String>(); //ConcurrentLinkedQueue并发编程

    //表达式封装
    @Resource
    private StudentService studentService;

    private List<Student> students;
    private Student student;
    private Long id;
    private String name;
    private Integer age;

    @Override
    public String execute() throws Exception{
        students = studentService.findAll();
        String nowname = queue.poll(); //poll线程安全方法
        student = studentService.getByName(nowname);
        return SUCCESS;
    }

    public String deleteStudent() throws Exception {
        studentService.deleteStudent(id);
        return SUCCESS;
    }

    public String findByName() throws Exception {
        String n = name;
        queue.offer(n);
        return SUCCESS;
    }

    //get set method
    public List<Student> getStudents() {
        return students;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

AddAction:

package com.gja.action;

import com.gja.entity.Student;
import com.gja.service.StudentService;
import com.opensymphony.xwork2.ActionSupport;
import javax.annotation.Resource;

public class AddAction extends ActionSupport {

    //表达式封装
    @Resource
    private StudentService studentService;
    private Student student;
    private String name;
    private Integer age;

    @Override
    public String execute() throws Exception{
        return SUCCESS;
    }

    public String addStudent() throws Exception {
        String name = student.getName();
        Integer age = student.getAge();
        if (age == null || name == null || name.equals("")) {
            return "noInput";
        }
        if (age < 18 || age > 120) {
            return ERROR;
        }
        studentService.addStudent(student);
        return SUCCESS;
    }

    //get set method
    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

UpdateAction:

package com.gja.action;

import com.gja.entity.Student;
import com.gja.service.StudentService;
import com.opensymphony.xwork2.ActionSupport;
import javax.annotation.Resource;

public class UpdateAction extends ActionSupport {

    //表达式封装
    @Resource
    private StudentService studentService;
    private Student student;
    private Long id;
    private String name;
    private Integer age;

    @Override
    public String execute() throws Exception{
        return SUCCESS;
    }

    public String updateStudent() throws Exception{
        String name = student.getName();
        Integer age = student.getAge();
        if (age == null || name == null || name.equals("")) {
            return "noInput";
        }
        if (age < 0 || age > 120) {
            return ERROR;
        }
        studentService.updateStudent(student);
        return SUCCESS;
    }

    //get set method

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

StudentMapper.xml:

<?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.gja.dao.StudentDao">

    <select id="findByName" parameterType="string" resultType="com.gja.entity.Student">
        select * from student where name = #{name}
    </select>

    <insert id="add" parameterType="com.gja.entity.Student" useGeneratedKeys="true">
        insert into student(name,age) values(#{name},#{age})
    </insert>

    <delete id="delete" parameterType="long">
        delete from student where id = #{id}
    </delete>

    <update id="update" parameterType="com.gja.entity.Student">
        update student set name = #{name}, age = #{age} where id = #{id}
    </update>

    <select id="findAll" resultType="com.gja.entity.Student">
        select * from student
    </select>
</mapper>

struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package namespace="/student" name="stu" extends="struts-default">

        <action name="list" class="com.gja.action.StudentAction">
            <result>/WEB-INF/views/jsp/student/list-success.jsp</result>
        </action>

        <action name="error" class="com.gja.action.StudentAction">
            <result>/WEB-INF/views/jsp/student/error.jsp</result>
        </action>

        <action name="noInput" class="com.gja.action.StudentAction">
            <result>/WEB-INF/views/jsp/student/nullInput.jsp</result>
        </action>

        <action name="addStu" class="com.gja.action.AddAction" method="addStudent">
            <result name="success" type="redirect">list.action</result>
            <result name="error" type="redirect">error.action</result>
            <result name="noInput" type="redirect">noInput.action</result>
        </action>
        <action name="add" class="com.gja.action.AddAction">
            <result>/WEB-INF/views/jsp/student/add.jsp</result>
        </action>

        <action name="delete" class="com.gja.action.StudentAction" method="deleteStudent">
            <result type="redirect">list.action</result>
        </action>

        <action name="updateStu" class="com.gja.action.UpdateAction" method="updateStudent">
            <result name="success" type="redirect">list.action</result>
            <result name="error" type="redirect">error.action</result>
            <result name="noInput" type="redirect">noInput.action</result>
        </action>
        <action name="update" class="com.gja.action.UpdateAction">
            <result>/WEB-INF/views/jsp/student/update.jsp</result>
        </action>

        <action name="getByName" class="com.gja.action.StudentAction" method="findByName">
            <result type="redirect">list.action</result>
        </action>

    </package>
</struts>

mybatis-config.xml:

<?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>
    <!-- 修改mybatis的原始的配置信息 -->
    <settings>
        <!-- 启动延迟加载 -->
        <setting name="lazyLoadingEnabled" value="true"/>
        <!-- 设置为false之后,表示在访问many方的属性的时候 ,不触发延迟-->
        <setting name="aggressiveLazyLoading" value="false"/>
        <!-- 访问Object中的clone方法时候触发延迟加载 -->
        <setting name="lazyLoadTriggerMethods" value="clone"/>
    </settings>
</configuration>

struts-default.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <!--开发模式,在struts.xml配置文件中修改后不用重新部署项目.设为true,这样可以打印出更详细的错误信息-->
    <constant name="struts.devMode" value="true"></constant>
    <!-- 设置默认的locale和字符编码 -->
    <constant name="struts.locale" value="zh_CN"></constant>
    <constant name="struts.i18n.encoding" value="utf-8"></constant>


    <include file="struts/struts.xml"></include>
</struts>

db.properties:

db.driverClassName=com.mysql.cj.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/ssmbuild?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
db.username=root
db.password=123456

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd" >


    <import resource="applicationContext-action.xml"/>
    <import resource="applicationContext-dao.xml"/>
    <import resource="applicationContext-service.xml"/>
</beans>

applicationContext-dao.xml:

<?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
    http://www.springframework.org/schema/context/spring-context.xsd">

    <context:property-placeholder location="classpath:db.properties" system-properties-mode="NEVER"/>
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="mapperLocations" value="classpath:/mapper/StudentMapper.xml"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.gja.entity"/>
    </bean>

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <property name="driverClassName" value="${db.driverClassName}"/>
        <property name="url" value="${db.url}"/>
        <property name="username" value="${db.username}"/>
        <property name="password" value="${db.password}"/>
    </bean>

    <!-- 加载 mapper.xml对应的接口 配置文件 -->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 给出需要扫描mapper接口包 -->
        <property name="basePackage" value="com.gja.dao"/>
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>
</beans>

applicationContext-service.xml:

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- 扫描service包下所有使用注解的类型 -->
    <context:component-scan base-package="com.gja.service"/>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- 配置基于注解的声明式事务 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

applicationContext-action.xml:

<?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:component-scan base-package="com.gja"/>

</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">

  <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>

  <!-- struts2核心配置 -->
  <filter>
    <!-- 过滤器名称,自定义,命名为struts2 -->
    <filter-name>Struts2</filter-name>
    <!-- 过滤器核心类 -->
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    <init-param>
      <param-name>filterConfig</param-name>
      <param-value>classpath:struts-default.xml</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <!-- 过滤器名称,自定义,命名为struts2 -->
    <filter-name>Struts2</filter-name>
    <!-- 过滤范围 -->
    <url-pattern>*.action</url-pattern>
  </filter-mapping>
  
</web-app>

list-success.jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>students</title>
<%--    样式--%>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
</head>
<body>

<s:form action="getByName" theme="simple" class="ui attached segment" namespace="/student">
    <s:textfield name="name" placeholder="输入姓名查找" ></s:textfield>
    <s:submit value="查询"></s:submit><s:fielderror value="error:"></s:fielderror>
    <a href="${pageContext.servletContext.contextPath}/student/add.action" class="ui button mini teal" style="margin-left: 30px">添加</a>
</s:form>

<br>

<table class="ui celled attached table" style="margin-top: 40px !important;">
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>年龄</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${students}" var="s">
        <tr>
            <td>${s.id}</td><td>${s.name}</td><td>${s.age}</td>
            <td>
                <a href="/student/update.action?id=${s.id}" class="ui button mini pink">修改</a>
                <a href="/student/delete.action?id=${s.id}" class="ui button mini teal">删除</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<c:out value="${student.id}"/>
<c:out value="${student.name}"/>
<c:out value="${student.age}"/>
</body>
</html>

add.jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>add</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
</head>
<body>

<s:form action="addStu" class="ui form" namespace="/student">
    <s:label value="姓名:"></s:label>
    <s:textfield name="student.name"></s:textfield>
    <s:label value="年龄:"></s:label>
    <s:textfield name="student.age" type="number" value="0"></s:textfield>
    <s:submit value="提交" class="ui button"></s:submit><s:fielderror value="error:"></s:fielderror>
</s:form>


</body>
</html>

update.jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>update</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
</head>
<body>
<s:form action="updateStu" class="ui form" namespace="/student">
    <s:label value="id:"></s:label>
    <s:textfield name="student.id"></s:textfield>
    <s:label value="姓名:"></s:label>
    <s:textfield name="student.name"></s:textfield>
    <s:label value="年龄:"></s:label>
    <s:textfield name="student.age" type="number" value="0"></s:textfield>
    <s:submit value="提交" class="ui button"></s:submit><s:fielderror value="error:"></s:fielderror>
</s:form>
</body>
</html>

error.jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>error</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
</head>
<body>
<table class="ui celled attached table" style="margin-top: 40px !important;">
<td>年龄输入不正确</td>
</table>
</body>
</html>

nullInput.jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>error</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
</head>
<body>
<table class="ui celled attached table" style="margin-top: 40px !important;">
    <td>没有输入</td>
</table>
</body>
</html>

在struts.xml文件中可以看到

<package namespace="/student" name="stu" extends="struts-default">

    <action name="list" class="com.gja.action.StudentAction">
        <result>/WEB-INF/views/jsp/student/list-success.jsp</result>
    </action>

启动运行是http://localhost:8080/student/list.action

数据库:

运行效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值