接触Struts2不是很久,想尝试用一下,就在web.xml
welcome-file下设计直接跳转到指定的action
There is no Action mapped for namespace / and action name
直接输action没有问题,配置没有问题
查了一些资料,原来问题出现在
tomcat 会去检查有没有在相应的目录下有没有login.do这个文件.
解决方法一:在对应的目录下建立对应的文件 之后再跳转都随你了(测试不带后缀的不可以)
解决方法二:(因上面的解决方法 只在Tomcat服务器下适用,别的不一定适用)
创建一个Filter 过滤访问地址,通用
这样处理的话 welcome-file-list 对应的file 写什么都无所谓
这里关联到Filter(过滤器) 再学习一下
http://guifan.iteye.com/blog/1631513
参考页面:
http://blog.ziki.cn/284.html
......
--------------------------------------------------------------------------
交流群:81552084
--------------------------------------------------------------------------
welcome-file下设计直接跳转到指定的action
There is no Action mapped for namespace / and action name
直接输action没有问题,配置没有问题
查了一些资料,原来问题出现在
<welcome-file-list>
<welcome-file>login.do</welcome-file>
</welcome-file-list>
tomcat 会去检查有没有在相应的目录下有没有login.do这个文件.
解决方法一:在对应的目录下建立对应的文件 之后再跳转都随你了(测试不带后缀的不可以)
解决方法二:(因上面的解决方法 只在Tomcat服务器下适用,别的不一定适用)
创建一个Filter 过滤访问地址,通用
package com.lc.common;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
public class WelcomeFileFilter implements Filter {
public void destroy() {
indexFile = null;
}
private String indexFile;
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
String servletPath = httpServletRequest.getServletPath();
String contextPath = httpServletRequest.getContextPath();
String requestURI = httpServletRequest.getRequestURI();
System.out.println(requestURI);
if (contextPath.equalsIgnoreCase(requestURI) || (contextPath + "/").equalsIgnoreCase(requestURI)) {
String url = "";
if (indexFile.startsWith("/")) {
url = contextPath + indexFile;
} else {
url = contextPath + "/" + indexFile;
}
httpServletResponse.sendRedirect(url);
} else {
chain.doFilter(request, response);
}
}
public void init(FilterConfig arg0) throws ServletException {
indexFile = "login";
String x = arg0.getInitParameter("indexFile");
if (StringUtils.isNotBlank(x)) {
indexFile = x;
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>welcome</filter-name>
<filter-class>com.lc.common.WelcomeFileFilter</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>welcome</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.....</welcome-file>
</welcome-file-list>
</web-app>
这样处理的话 welcome-file-list 对应的file 写什么都无所谓
这里关联到Filter(过滤器) 再学习一下
http://guifan.iteye.com/blog/1631513
参考页面:
http://blog.ziki.cn/284.html
......
--------------------------------------------------------------------------
交流群:81552084
--------------------------------------------------------------------------