idea maven新建struts2项目
环境:
IDEA
java1.8
struts2-core 2.5.18

一路下一步,名字自己随便填,
项目建好后修改pom.xml文件,加入struts2-core

添加tomcat:

+号添加web

添加tomcat

在resources下新建struts.xml

如果出现错误,Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
手动删除再添加这个,然后修改tomcat的设置。

运行举例:

public class HelloWorldAction {
private String name;
public String execute() throws Exception {
if (getName().equals("") || getName() == null)
return "error";
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
HelloWorldAction.java
<?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.enable.DynamicMethodInvocation" value="true" /> <package name="default" extends="struts-default">
<default-action-ref name="index" />
<action name="index" >
<result name="success">/index.jsp</result>
</action>
<action name="hello" class="HelloWorldAction" method="execute">
<result name="success">/HelloWorld.jsp</result>
<result name="error">/Error.jsp</result>
</action>
</package>
</struts>
struts.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">
<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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
web.xml
<%--
Created by IntelliJ IDEA.
User: Flyuz
Date: 2018/12/19
Time: 20:22
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World Struts2</h1>
<form action="hello">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Enter"/>
</form>
</body>
</html>
index.jsp
<%--
Created by IntelliJ IDEA.
User: Flyuz
Date: 2018/12/19
Time: 20:26
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
Hello World, Welcome! <s:property value="name"/>
</body>
</html>
HelloWorld.jsp
idea maven新建struts2项目的更多相关文章
- Eclipse下Maven新建Web项目index.jsp报错完美解决(war包)
Eclipse下Maven新建Web项目步骤 1. 2. 3. 4. 5. 问题描述 最近用eclipse新建了一个maven项目,结果刚新建完成index.jsp页面就报错了,先把错误信息贴出来看看 ...
- maven新建web项目提示The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
maven新建web项目提示The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu ...
- Maven的学习资料收集--(五)使用Maven构建Struts2项目
在前两篇博客中,使用Maven构建了Web项目,在这篇博客中写一下,怎样构建一个简单的Struts2项目. 在准备过程中发现,要使用好Maven,个人觉得要好好利用这两个网站: http://mvnr ...
- 用Maven新建Web项目时报错
在cmd下,用mvn命令 mvn archetype:create -DgroupId=org.seckill -DartifactId=seckill -DarchetypeArtifactId=m ...
- Maven构建Struts2项目
1.添加Struts2依赖 这里主需要在pom.xml中添加一个struts-core的依赖即可: <project xmlns="http://maven.apache.org/PO ...
- Maven3路程(四)用Maven创建Struts2项目
采用struts版本:struts-2.3.8 一.创建一个web项目 参考前面文章,项目名:maven-struts-demo. 二.配置pom.xml文件添加struts2依赖 <proje ...
- JAVA学习4:用Maven创建Struts2项目
采用struts版本:struts-2.3.8 一.创建一个web项目 参考前面文章,项目名:maven-struts-demo. 二.配置pom.xml文件添加struts2依赖 <pro ...
- Maven新建webapp项目index.jsp报错
最近用eclipse新建了一个maven项目,结果刚新建完成index.jsp页面就报错了,先把错误信息贴出来看看 后来就找资料,结果发现两种解决办法,希望可以帮助用得上的人! 第一种:直接在pom. ...
- eclipse maven新建springMVC项目(原创)
1.配置eclipse maven 2.新建maven项目 3.新建src/main/java,更新pom <project xmlns="http://maven.apache.or ...
随机推荐
- Junit Test 的时候出错java.lang.IllegalStateException: Failed to load ApplicationContext
问题原因 JDK1.8 spring版本3.2.0RELEASE JDK和spring版本不兼容 解决方法 1.降低JDK版本到1.7 2.将spring的版本升级到4.0.0RELEASE或者 ...
- [iOS]UIScrollView嵌套UITableView,超出屏幕的cell点击不了问题
最初我是用UIScrollView嵌套了一个UIView,然后UIView里面嵌套UITableView,这样cell 就会超出屏幕那一部分点击不了. 解决方法如下,UITableView拖出来,作为 ...
- systemd 配置文件
[Unit]区块通常是配置文件的第一个区块,用来定义 Unit 的元数据,以及配置与其他 Unit 的关系.它的主要字段如下. Description:简短描述 Documentation:文档地址 ...
- centos7 安装docker-ce ,最新版本docker,docker阿里云加速
直接用yum install docker -y安装的docker版本为1.12,但是docker发展很快,现在都17.06.2了.docker-ce是指docker的社区版 卸载老版本的 docke ...
- 读取properties文件并获取属性值
1.Properties与ResourceBundle 两个类都可以读取属性文件中以key/value形式存储的键值对,ResourceBundle读取属性文件时操作相对简单. 2.Propertie ...
- VUE+WebPack实现精美前端游戏:CardBattle的游戏场景设置
C:\Users\ZHONGZHENHUA\cardBattle\src\App.vue src/App.vue <template> <div id="app" ...
- 【hdu6148】Valley Numer【数位dp模板题】
题意 对于每组数据给出一个整数n(length(n)<=100),找出不大于n的数字中有多少是Valley Numer.对于Valley的定义是它每一位的数字要么是递增,要么是递减,要么是先递减 ...
- 爬虫解析:XPath总结
1.加载 XML 文档 所有现代浏览器都支持使用 XMLHttpRequest 来加载 XML 文档的方法. 针对大多数现代浏览器的代码: var xmlhttp=new XMLHttpRequest ...
- 开发微信小程序入门教程,含破解工具
2016年09月21日晚 微信发不了微信“小程序”的内测版,一时间整个互联网都炸了锅.个大新闻.论坛都在讨论这个事情. 作为互联网的一猿,我们怎能不紧跟时代的脚步.于是第二天上午也对微信发布的“小程序 ...
- 洛谷 P2850 [USACO06DEC]虫洞Wormholes 判负环
虫洞(wormhole) FJ 在农场上闲逛时,发现他的农场里有很多虫洞.虫洞是一条特殊的有向路径,当 FJ 从它的一头走到另一头后,他将被传送到过去的某个时刻.FJ 的每个农场包括 N(1<= ...