在struts2中设置一个<form>的action域时,可以用.action,也可以用<s:form>。我想试试不用这两种方式,而是直接写<form action="<struts.xml中的action名称>">,结果总报404错误。看了搜索没有太好的总结,各位有什么经验?
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">

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
  
   <filter>
<filter-name>struts2hello</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2hello</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.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
   <struts>
<package name="struts2hello"  extends="struts-default">
<action name="Login" class="struts2.hello.HelloAction">
<result name="success">/result.jsp</result>
</action>
</package>
   </struts>
==========================
index.jsp内容:
<form action="/struts2hello/Login" method="post">
name:<input type="text" name="name" size=19>
password:<input type="password" name="password" size=20>
<input type=submit>
</form>
==========================
HelloAction类内容:
package struts2.hello;import com.opensymphony.xwork2.ActionSupport;public class HelloAction extends ActionSupport{
public static final long serialVerionUID=0l; 
private String name;
private String password; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
}

public String execute(){
return SUCCESS;
}}
我也试了在strust.xml中增加namespace的方法,结果还是一样,郁闷中

解决方案 »

  1.   

    如果你这个jsp页面是在webroot根目录下的话:
    把<form action="/struts2hello/Login" method="post"> 
    改成:
    <form action="Login.action" method="post"> 
      

  2.   

    不好意思,我的本意是这么定义form的:
    <form action="Login" method="post"> 
      

  3.   

    Login.action肯定能用,我就是想用Login试试,按struts2原理来讲,如果继承ActionSupport,可以省略.action。我想看看省略后是什么情况
      

  4.   

    一个是用.action,另一个是用s:form,看来就两种结论了?