我疯了。我几个小时以来一直在寻找我的错误。
我的表单不会进入操作。但我检查了1000次。一切都拼写正确。 我不知道... 请帮忙!
我心爱的错误信息:
HTTP状态404 - 没有为操作定义结果 de.nordakademie.librarymgmt.action.CreatePubAction和结果输入
输入状态报告
消息没有为操作定义结果 de.nordakademie.librarymgmt.action.CreatePubAction和结果输入
说明请求的资源不可用。
Apache Tomcat / 7.0.42
这就是jsp。在文件夹jsp中调用createPublication.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<h3>Fügen Sie eine neue Publikation hinzu</h3>
<s:form action="createPubAction">
<s:textfield key="publication.title" />
<%-- <s:textfield key="publication.author" /> --%>
<s:textfield key="publication.publisher" />
<s:textfield key="publication.publishment" />
<s:textfield key="publication.isbn" />
<s:textfield key="publication.stock" />
<s:if test="%{publicationtypes.isEmpty()}">
keine Publikationstypen
</s:if>
<s:else>
<s:select Listkey="publication.type" list="publicationtypes.{type}" />
</s:else>
<s:if test="%{keywords.isEmpty()}">
keine Schlagwörter
</s:if>
<s:else>
<s:checkboxlist key="publication.keyword" label="Schlagworte"
name="keywordsL1" list="keywords.{name}" />
</s:else>
<s:submit label="save" value="Speichern" />
</s:form>
</body>
</html>
struts.xml中 newPublication正在调用我需要输入所需信息的页面
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- mapping of global-results and global-exceptions -->
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<default-action-ref name="Start" />
<action name="Start" class="de.nordakademie.librarymgmt.action.StartAction">
<result type="tiles" name="success">main</result>
</action>
<action name="newPublication"
class="de.nordakademie.librarymgmt.action.NewPublication">
<result type="tiles" name="success">createPublication</result>
</action>
<action name="createPubAction"
class="de.nordakademie.librarymgmt.action.CreatePubAction">
<result type="tiles" name="success">catalog</result>
</action>
<action name="catalogAction"
class="de.nordakademie.librarymgmt.action.navi.CatalogAction">
<result type="tiles" name="success">catalog</result>
</action>
</package>
</struts>
Tiles文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="main" template="/jsp/main.jsp">
<put-attribute name="title" value="Dashboard"/>
<put-attribute name="menu" value="/jsp/menu.jsp"/>
<put-attribute name="header" value="/jsp/header.jsp"/>
<put-attribute name="content" value="/jsp/start.jsp"/>
</definition>
<definition name="dashboard" extends="main">
<put-attribute name="title" value="Dashboard"/>
<put-attribute name="content" value="/jsp/start.jsp"/>
</definition>
<definition name="rental" extends="main">
<put-attribute name="title" value="Verleihvorgänge"/>
<put-attribute name="content" value="/jsp/rental.jsp"/>
</definition>
<definition name="catalog" extends="main">
<put-attribute name="title" value="Katalog"/>
<put-attribute name="content" value="/jsp/catalog.jsp"/>
</definition>
<definition name="createPublication" extends="main">
<put-attribute name="title" value="Neue Publikation erstellen"/>
<put-attribute name="content" value="/jsp/createPublication.jsp"/>
</definition>
</tiles-definitions>
最后但并非最不重要的是:
package de.nordakademie.librarymgmt.action;
import com.opensymphony.xwork2.ActionSupport;
import de.nordakademie.librarymgmt.model.Publication;
import de.nordakademie.librarymgmt.service.IPublicationService;
public class CreatePubAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private Publication publication;
private IPublicationService publicationService;
@Override
public String execute() throws Exception {
try{
publicationService.savePublication(publication);
return SUCCESS;
} catch(Exception e){
e.printStackTrace();
return ERROR;
}
}
public Publication getPublication() {
return publication;
}
public void setPublication(Publication publication) {
this.publication = publication;
}
public IPublicationService getPublicationService() {
return publicationService;
}
public void setPublicationService(IPublicationService publicationService) {
this.publicationService = publicationService;
}
}
答案 0 :(得分:0)
您是否在日志中看到过堆栈跟踪?
我冒昧地猜测你正在调用你的ERROR响应而你没有映射它。您可以尝试在tile配置中明确定义ERROR结果吗?
我最初的直觉(来自处理一个非常类似的问题)是你的一个JSP文件在tiles配置中拼写错误或者没有包含在Web应用程序中。我会仔细检查一下。
答案 1 :(得分:0)
<action name="createPubAction"
class="de.nordakademie.librarymgmt.action.CreatePubAction">
<result type="tiles" name="success">catalog</result>
</action>
您只定义了success
。错误说,该操作正在返回input
结果,如上所示,如果遇到input
结果,则没有关于该怎么做的定义。
快速修复可以是:
<action name="createPubAction"
class="de.nordakademie.librarymgmt.action.CreatePubAction">
<result type="tiles" name="success">catalog</result>
<result type="tiles" name="input">catalog</result>
</action>