Struts的“No action config found for the specified url”错误

mayi1989826 2009-05-31 03:25:01
No action config found for the specified url.是struts-config.xml的配置问题,但是仔细改了几遍,也问了老师,始终无法解决。


1,struts-config的配置文件

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.mayn.actionForm.LoginActionForm"/>
</form-beans>

<action-mappings>
<action path="/login"
type="com.mayn.action.LoginAction"
name="loginForm"
scope="request">
<forward name="success" path="/information/success.jsp"/>
<forward name="failure" path="/information/error.jsp"/>
</action>
</action-mappings>
</struts-config>





2,web.xml的配置文件

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>Struts Blank Application</display-name>

<!-- Standard Action Servlet Configuration -->
<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>2</load-on-startup>
</servlet>

<!-- Standard Action Servlet Mapping -->

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>



3,login.jsp

<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>Login Page</title>
</head>
<body>
<h1>User Login</h1>
<hr>
<form action="login.do" method="post">
Username: <input type="text" name="username"><br/>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
<input type="reset" value="Reset"><br/>
</form>
</body>
</html>





4,LoginAction.java

package com.mayn.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;

import com.mayn.actionform.LoginActionForm;
import com.mayn.exception.PasswordErrorException;
import com.mayn.exception.UserNotFoundException;
import com.mayn.manager.UserManager;

public class LoginAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception
{
LoginActionForm loginActionForm = (LoginActionForm)form;
String username = loginActionForm.getUsername();
String password = loginActionForm.getPassword();

// if("mayn".equals(username) && "mayn".equals(password))
// {
// System.out.println("Has Logged");
// request.setAttribute("username", username);
// return mapping.findForward("success");
// }
// else
// {
// System.out.println("Logged was failured!");
// return mapping.findForward("failure");
// }
String errorInfo = null;
try
{
UserManager.getInstance().validate(username, password);
request.setAttribute("username", username);
return mapping.findForward("success");
}catch (UserNotFoundException unfe)
{
unfe.printStackTrace();
errorInfo = "Your username [" + username +"] is error!";
}
catch (PasswordErrorException pee)
{
pee.printStackTrace();
errorInfo = "Your password is error!";
}

request.setAttribute("errorInfo", errorInfo);
return mapping.findForward("failure");
}
}



5,另有LoginActionForm.java在com.mayn.actionform包中,success.jsp和error.jsp也面在WEB-INF/information/路径下。
...全文
159 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
a1405 2009-06-01
  • 打赏
  • 举报
回复
1.先看看服务器启动时,用什么报错没
2.login.jsp页应该直接放到web跟目录下,否则提交时url不正确
正确的url应该为:项目名/login.do
3.你的<forward name="success" path="/information/success.jsp"/>
配置有误,success.jsp页应该放在根目录下的information目录下而不是在WEB-INF/information/
但这不是造成你出错的原因。
三月暖阳 2009-05-31
  • 打赏
  • 举报
回复
仔细的检查你的struts的配置文件,action的路径看看写错没有,这种问题应该不是技术的
yhaind 2009-05-31
  • 打赏
  • 举报
回复
这种简单的问题静下心仔细检查下应该就差不多了.

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧