IntelliJ IDEA2021.2 引入struts2框架完成第一个程序

2021/9/17 12:35:07

本文主要是介绍IntelliJ IDEA2021.2 引入struts2框架完成第一个程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

IntelliJ IDEA2021.2引入struts2框架实现跳转程序

1.在web程序中使struts2框架需要到官网下载需要的jar包,官网链接如下:

https://struts.apache.org/download.cgi#struts2510

1-1
上图中红框中的min是官方提供的对于初学者的基础包,all是完整包但体积较大,大家自行选择。
下载解压如图:
1-2

  1. 创建一个JAVA EE项目
    2-1
    在更新到2021版本之后,官方已经取消图中红框的选项了,要实现如图的效果需要下载插件Struts2
    2-2
    如图2-3

勾选Web Applicatiion 和Struts2
在Libraries中选择Use libraries

2-3

create选择第一步中解压好的路径全选jar包,确定

2-4
2. 至此,准备工作完成,完成一个简单程序
当创建完成后,会自动在src和WEB-INF下产生struts.xml和web.xml配置文件
项目结构如图:3-1
4. 相关代码
struts.xml

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

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
    <package name="Hello" extends="struts-default">
        <action name="Hello">
            <result>
                HelloWorld.jsp
            </result>
        </action>
    </package>
</struts>

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">
</web-app>

HelloWoeld.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div align="center">
    <h1>Hello World</h1>
</div>
</body>
</html>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <h1>
    <a href="HelloWorld.jsp">登陆</a>
  </h1>
  </body>

实现界面:
4-1
实现跳转:
4-2

完结撒花



这篇关于IntelliJ IDEA2021.2 引入struts2框架完成第一个程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程