There is no Action mapped for namespace [/] and action name [LoginAction_login] associated with context path [/wuliu].

房乔 发布于 2017/01/16 12:47
阅读 1K+
收藏 0

LoginAction.java代码


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;


import com.lee.wuliu.dao.UserDao;
import com.lee.wuliu.domain.Line;
import com.lee.wuliu.domain.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


/**
 * 
 * @struts.action path="/login" name="loginForm" input="/form/login.jsp"
 *                scope="request" validate="true"
 */
@Controller("LoginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport implements ModelDriven<User> ,ServletRequestAware, ServletResponseAware {
/*
* Generated Methods
*/
private String password;


/** powerID property */
private String powerID;


/** username property */
private String username;


public String getPassword() {
return password;
}


public void setPassword(String password) {
this.password = password;
}


public String getPowerID() {
return powerID;
}


public void setPowerID(String powerID) {
this.powerID = powerID;
}


public String getUsername() {
return username;
}


public void setUsername(String username) {
this.username = username;
}


public static ApplicationContext context;
static {
context = new ClassPathXmlApplicationContext("com/lee/wuliu/spring/applicationContext.xml");
}


private HttpServletRequest request;


public void setServletRequest(HttpServletRequest req) {
// TODO Auto-generated method stub
this.request = req;
}


private HttpServletResponse response;


public void setServletResponse(HttpServletResponse arg0) {
// TODO Auto-generated method stub
this.response = arg0;
}


/**
* Method execute

* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public String login() {
// LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method
// stub
UserDao dao = (UserDao) context.getBean("UserDao");
User u = dao.login(this.getUsername().trim(), this.getPassword().trim(),
Integer.parseInt(request.getParameter("powerID")));


String msg = null;
if (u != null) {
HttpSession session = request.getSession();
session.setAttribute("UserSession", u);
if (this.getPowerID().equals("1")) {
return "super";
} else if (this.getPowerID().equals("2")) {
return "manager";
} else if (this.getPowerID().equals("3")) {
return "operater";
}
} else
msg = "<font color=red>用户名或密码错误!请重试!</font>";
request.setAttribute("Login_Error", msg);
return "success";//返回登录界面
}


public String loginOut() {
//LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method
// stub
HttpSession session = request.getSession();
User u = (User) session.getAttribute("UserSession");
if (u != null) {
session.setAttribute("UserSession", null);
}
return "error";
}


public User getModel() {
// TODO Auto-generated method stub
return this.getModel();
}
}


struts-login.xml

<?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">


<?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">


<struts>
<package name="login" namespace="/" extends="interceptor">
<action name="loginAction_*" method="{1}" class="LoginAction">

<result name="success">index.jsp
</result>
<result name="error">index.jsp
</result>


</action>


</package>
</struts>




struts.xml

<?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">


<struts>
<constant name="struts.ui.theme" value="simple"></constant>
<constant name="struts.devMode" value="true"/>
<include file="com/lee/wuliu/struts/struts-login.xml"></include>
</struts>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/lee/wuliu/spring/applicationContext.xml</param-value>
</context-param>

<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
 
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> 
</web-app>


错误信息:

There is no Action mapped for namespace [/] and action name [LoginAction_login] associated with context path [/wuliu]. - [unknown location]

请问这要怎么解决?

加载中
0
廖小白
廖小白
没找到你的action,看你请求与配置文件是否一致
返回顶部
顶部