我正在使用Struts 1.2应用程序,其中包含以下web.xml和struts-config.xml
的web.xml
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
的struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="Welcome"
type="com.mugil.tutor.action.Sample" />
</form-beans>
<action-mappings>
<action path="/Welcome" name="Welcome" type="com.mugil.tutor.action.Sample">
<forward name="success" path="/welcome.jsp"/>
</action>
</action-mappings>
</struts-config>
Files的目录结构如下所示
我想在welcome.jsp中显示欢迎消息。这应该在我从Sample.java收到成功消息后发生
Sample.java
package com.mugil.tutor.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class Sample extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String target = "success";
return mapping.findForward(target);
}
}
的welcome.jsp
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to Struts 1.2</h1>
</body>
</html>
我不知道我哪里出错了。当我尝试修复错误信息时会显示不同的错误消息。
答案 0 :(得分:1)
我认为这是因为您已将ActionServlet
映射到网址格式/*
。我不认为Struts 1处理“无扩展”的URL,它会干扰/welcome.jsp
的路径。尝试将网址格式更改为*.do
或其他后缀。