新建struts2纯净项目教程(idea)

环境需要 

  • comcat8.5.73
  • Maven3.8.4
  • jdk1.8
  1. 新建项目

注意把对钩打上 create from archeType。

 

选择Maven的文件位置

 修改pom.xml

 插入一下代码

<dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>2.5.29</version>
    </dependency>

 重构项目

新建文件:参考目录 

新建 web.xml

 

 替换为以下代码

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

 新建struts.xml  替换为以下代码

这里配置了扩展名.do

<?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>
<!--    打开开发模式  日志会变得详细-->
    <constant name="struts.devMode" value="true"/>
<!--    打开动态方法-->
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<!--    修改struts2的action的扩展名为.do-->
    <constant name="struts.action.extension" value="do"/>

    <package name="test" extends="struts-default">
        <action name="first" class="org.example.FirstAction">
            <result>/first.jsp</result>
        </action>
       
    </package>
</struts>

 点击org.example右键新建

 在org.example包中新建FirstAction.java

package org.example;

/**
 * @author pig
 */
public class FirstAction {

    public String execute() {

        return "success";
    }

}

在webapp中新建first.jsp文件

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>first.jsp</title>
</head>
<body>
first------------------------------

</body>
</html>

添加tomcat服务器

 

 

 启动项目                debug

看到helloWorld!

浏览器地址栏输入localhost:9999/first.do

遇到问题 欢迎评论

 加油陌生人

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kaiyu0426

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值