我正在尝试创建一个没有struts.xml文件且仅使用注释的struts项目。这不是我的想法,我在此网址上跟踪示例:https://www.tutorialspoint.com/struts_2/struts_annotations.htm
我认为在复制教程中描述的示例方面,我有一切正确。当我运行应用程序但是我收到500错误,如下图所示。
Employee.java源代码低于这句话。
package com.tutorialspoint.struts2;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.validator.annotations.*;
@Results({
@Result(name="success", location="/success.jsp"),
@Result(name="input", location="/index.jsp")
})
public class Employee extends ActionSupport {
private String name;
private int age;
@Action(value="/empinfo")
public String execute() {
return SUCCESS;
}
@RequiredFieldValidator(message="The name is required")
public String getName()
{
return name;
}
public void setName(String name) {
this.name = name;
}
@IntRangeFieldValidator(message="Age must be in between 28 and 65", min="29", max="65")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
我的web.xml
文件编码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>StrutsAnnotations</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>struts.devMode</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
构建和部署到Tomcat服务器时收到的错误。
此错误表示由于某种原因未阅读该课程。该类是上面显示的项目屏幕截图和源代码中的Employee.java。我无法弄清楚为什么课不读。有没有人有任何想法?