日期:2014-05-17  浏览次数:20736 次

struts2奇怪的问题
jsp代码:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>My JSP 'index.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
  <form action="test.action" method="post">
  <input type="submit">
  </form>
  </body>
</html>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


</web-app>


struts.xml 配置
<?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="struts2" extends="struts-default">
<action name="test" class="com.nanfeng.action.Testaction">
<result>/index.jsp</result>
</action>
</package>
</struts>

action代码

package com.nanfeng.action;

import com.opensymphony.xwork2.ActionSupport;

public class Testaction extends ActionSupport {

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}


}

jar包:



为什么页面点提交按钮后就是找不到action 呢?请各位高手指导!

提示:HTTP Status 404 - /nanfeng/test.action

------解决方案--------------------
改了文件有没有重新布署下?
------解决方案--------------------
LZ anction中的方法很多吧》? 你的请求路径怎么知道要访问哪个呢?

这是写的一点儿Js版本的 希望有所帮助:
if( check_vipPass() && check_vipName() && chkPasswordconfirm() && checkEmail()){
document.forms[0].action = "vip/VipAction_add";
document.forms[0].method = "post";
document.forms[0].submit();
}