首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

struts2访问不到action有关问题

2013-11-30 
struts2访问不到action问题各位好:我在做一个登录页面,使用的框架是ssh集成,struts的版本是2.3.15.3登录页

struts2访问不到action问题
各位好:
      我在做一个登录页面,使用的框架是ssh集成,struts的版本是2.3.15.3
      登录页面提交报错
HTTP Status 404 - /*/loginAction.action
type Status report

message /*/loginAction.action

description The requested resource (/*/loginAction.action) is not available.

      不知道是web.xml配置错了?
       还是struts.xml配置错了?
      还是jsp页面的提交方式,提交地址错了?     
      麻烦大家帮忙给分析一下原因!先谢谢给位了!



web.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
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_3_0.xsd">
  <display-name>TSP</display-name>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.bonsoft.oa.filter.LoginFilter</filter-class>
<init-param>
<param-name>exclude</param-name>
<param-value>/jsp/zh_CN/login/login.jsp,
 /loginAction.action
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/servlet/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>/*</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>*.action</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/jsp/zh_CN/login/login.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>sessionTimeout</param-name>
<param-value>3000</param-value>
</context-param>
<listener>
<listener-class>com.bonsoft.oa.util.session.AppSessionListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/**/*.xml</param-value>
</context-param>
</web-app>

--------------------------------STRUTS的配置文件如下--------------

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <package name="web" extends="struts-default">
    
<action name="loginAction" class="com.ss.login.action.LoginAction" >
<result name="success">/hello.jsp</result>
</action>  

    </package>
</struts>



----------------------------------LOGIN页面如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">    
    <title>login</title>    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
  </head>
  <body>


    <form name="form1" action="loginAction.action" method="post">
      <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td  width="150" align="center">用户名:</td>
        <td  width="150" align="center"><input type="text" name="userName" id="userName"></td>
      </tr>
      <tr>
        <td  width="150" align="center">密码:</td>
        <td  width="150" align="center"><input type="password" name="loginPwd" id="loginPwd"></td>
      </tr>
      <tr >
      <td colspan="2" align="right"><input type="submit" value="登录"></td>    
      </tr>
    </table>
  </form>
  
  </body>
</html>



struts2配置问题 action找不到
[解决办法]
  <form name="form1" action="loginAction.action" method="post">不建议写相对路径的。如果对路径理解不清晰的话,经常出错。
[解决办法]
action="loginAction.action",action加上你的项目访问路径,如:你项目的访问路径是test,那就改成:/test/loginAction.action,看看你server.xml里面配置的context下的path
[解决办法]
你Action里面的方法是用的execute()
[解决办法]
配置没问题,这个错误提示说明loginAction.action 不是被当做一个Action处理的,而是当做路径处理的,和.jsp一样,个人觉得是在过滤器里面出现问题了
个人意见

热点排行