项目结构
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
HelloWorldAction.java
package com.example.web.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String execute() throws Exception {
System.out.println("Hello from HelloWorldAction class!");
setMessage("Hello World!");
return super.execute();
}
}
您好-world.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Hello World JSP</title>
</head>
<body>
This is message ${message}
</body>
</html>
当我链接到/ hello-world时,我只看到&#34;这是消息&#34;文本但没有$ {message}的值。此外,控制台不会通过System.out.println()显示消息。因此,HelloWorldAction不会调用。我做错了什么? 附:我使用struts2-convention-plugin-2.3.16.3。
插入log4j并查看日志后,这个问题就解决了。在我的课堂上没有asm图书馆