那么,在上面的form中点击submit后,在服务器端执行的是logonAction.java这个文件吗?
no! 是logonAction.class

解决方案 »

  1.   

    是的话,这个"/logon"还有什么用?
    不指明,谁知道action是什么呢??
      

  2.   

    .do是servletURL的映射,配置了servlet-mapping后,就可以这样访问了:在地址栏中输入
    http://localhost:8080/~~.do/logon.
      

  3.   

    2.".do"是什么意思?
    有这个的就去执行 Action
      

  4.   

    LogonAction.java The initial JSP submits its form to logon.do. If you check the servlet mappings in the example's web.xml you will see that requests for *.do files are directed to the Struts "action" servlet (an instance of ActionServlet). In the example, the ActionServlet refers to struts-config.xml for its own mappings (among other things), which is where we find the reference to logon.do: <!-- Process a user logon --> <action path="/logon" type="org.apache.struts.webapp.example.LogonAction" name="logonForm" scope="request" input="/logon.jsp" > </action> and a form bean to go with the "logonForm" action: <!-- Logon form bean --> <form-bean name="logonForm" type="org.apache.struts.webapp.example.LogonForm"  /> In the action mapping, the path property tells the ActionServlet to forward a request for logon.do to the LogonAction object. The input property tells the LogonAction object where it can pass control to get information from the user. Before passing the request to LogonAction, the ActionServlet looks for the LogonForm bean. If it finds it, the ActionServlet updates the bean by matching properties named in the HTTP request with properties named in the form bean. If it doesn't find the bean, ActionServlet creates it, so LogonAction can assume that it already exists. When called by the ActionServlet, LogonAction retrieves the username and password from the LogonForm bean. (If just created, the bean will return default values.) In the example, LogonAction then checks with the DatabaseServlet to see if the logon matches a registered user. If the logon doesn't match, LogonAction adds a message key to an error list. At the end of the routine, if the error list is not empty, LogonAction adds a User bean to the session context, and forwards control to its input form (login.jsp). Note that direct access to the DatabaseServlet should really be handled by a business-logic bean, and NOT by LogonAction. To quote the example's author "This should be considered a bug in the example."  If there are no errors, LogonAction places a user bean into the session context (replacing any prior user bean), and forwards control to the "success" action. Where that control actually goes is determined by the mappings in struts-config.xml. Before returning from a successful login, LogonAction also disposes of the LogonForm bean. This way, if the user returns to the index.jsp form later, it will be a clean form without the (old) login already entered. Note that LogonAction first checks to see if the scope has been set to "request", and then removes the bean from the request context, or otherwise from the default session context. The Struts best practice is to use request scope for single-page forms that contain all of your relevant properties, because there is no need to maintain such form beans across requests. Note that the example removes the LogonForm bean regardless of scope. This is for backward compatibility with earlier configurations. In your application, you should follow the advice of the configuration, and remove it only if the scope is set to "request". This way, the behavior can be changed just by editing struts-config.xml and reloading the application.  Go ahead and login successfully now, using the default username and password (user and pass).
      

  5.   

    /logon是路径,必须!不然找不到文件啊
    submit后,执行的是logon.jsp
      

  6.   

    to: cjxiaoh(风中水滴) 
    你能说的再明白点吗?
      

  7.   

    我都蒙了,submit后执行的是logon.jsp ?不会吧!
    AllError(错误大全) 挺有道理的.submit后执行的是logonAction.class吧"/logon是路径"什么意思?是http://localhost:8080/myapp/logon/   下吗,也没有这个路径呀?
      

  8.   

    "/logon"是去找 struts-config.xml里的
    <action    path="/logon"
                   type="org.apache.struts.webapp.example.LogonAction"
                   name="logonForm"
                  scope="request"
                  input="/logon.jsp">
    </action>
    所以去执行LogonAction, 如果你用<html:form> .do加不加一样的
    如果用<form action=....>要用/logon.do
    input 只是标记输入页面,如果你的form里有validation的代码,会把错误返回到这个页面
      

  9.   

    楼上说的精辟!
    其实/logon只是一个桥梁,调用action的时候,不用写诸如<html:form action="org.apache.struts.webapp.example.LogonAction" focus="username">的形式
    只要写成<html:form action="/logon" focus="username">
    再设置一下<action    path="/logon"
                   type="org.apache.struts.webapp.example.LogonAction"
                   ...
               >
    就行了 (:>使用.do 和不使用.do的区别:
    如果用struts的标签库<html:form>,则加不加都可,因为不用的话:直接按照指引到struts-config.xml里找到那个logonAction,然后执行;用的话:使用web.xml文件映射
    <servlet-mapping>
       <servlet-name>logon</servlet-name>
       <url-pattern>*.do</servlet-name>
    </servlet-mapping>
    把/logon.do映射成/logon,又回到前面说的那个执行方式啦