2013年11月14日星期四

Newbie Question : struts2 small demo post-deployment issues

 This post last edited by the scjtswj on 2013-11-14 10:13:48
Recent study struts2, wrote a small demo, web.xml content :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>samples</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

struts.xml Code:

<?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="struts2" namespace="" extends="struts-default">
<global-results>
<result name="login" type="redirect">/login.jsp</result>
</global-results>
<action name="userLogin" class="hs.homs.action.UserLoginAction">
<result name="success" type="redirect">/entrust.action</result>
<result name="error">/login.jsp</result>
</action>
<action name="entrust" class="hs.homs.action.EntrustAction">
<result name="success">main.jsp</result>
<result name="add">main.jsp</result>
</action>
<action name="entrust_add" method="add" class="hs.homs.action.EntrustAction">
<result name="success">main.jsp</result>
</action>
</package>
</struts>


code runs fine in eclipse , after running url is : http://localhost/demo2/login.jsp, a simple login screen, enter the user name password can not log into the inside pages , url is http: / / localhost/demo2 / beginning .

problem after deployment , the deployment directory structure:

which , web.xml in WEB-INF directory , struts.xml in build / classes directory

url is accessible after running http://localhost/login.jsp, normal open , click submit when given:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userLogin] associated with context path [].


after the release of the server.xml file (host node ) :

<Host name="localhost"  appBase="E:/JavaProjects/demo2_publish"
            unpackWARs="true" autoDeploy="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>


run in eclipse , is in a Tomcat v7.0 Server at localhost running , I looked at it also has its own server.xml file :

<Host appBase="E:/JavaProjects" autoDeploy="true" name="localhost" unpackWARs="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

       <Context docBase="demo2" path="/demo2" reloadable="true" source="org.eclipse.jst.jee.server:demo2"/>
      </Host>


After running I want to open the address without demo2 it has not been fix , solution ?
------ Solution ---------------------------------------- ----
submitted to the action when the namespace errors .
------ Solution ---------------------------------------- ----
namespace = " / "
------ Solution --------------------- -----------------------
you change the air or give him a name . Then form tag when adding namespace.
------ Solution ---------------------------------------- ----

------ Solution --------- -----------------------------------


Of course, you can refer to my example of this free program , which is also used struts, I believe that your help is still there

http://blog.csdn.net/shadowsick/article/details/8903278
------ Solution ------------------- -------------------------
named yet ?
------ Solution ---------------------------------------- ----

<?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="struts2" extends="struts-default">
        <global-results>
            <result name="login" type="redirect">/login.jsp</result>
        </global-results>
        <action name="userLogin" class="hs.homs.action.UserLoginAction">
            <result name="success" type="redirect">/entrust.action</result>
            <result name="error">/login.jsp</result>
        </action>
        <action name="entrust" class="hs.homs.action.EntrustAction">
            <result name="success">main.jsp</result>
            <result name="add">main.jsp</result>
        </action>
        <action name="entrust_add" method="add" class="hs.homs.action.EntrustAction">
            <result name="success">main.jsp</result>
        </action>
    </package>
</struts>

------ Solution ------------------------------ --------------
+1024
------ Solution --------------------- -----------------------

  
with this configuration ?   
I replaced this configuration   
  
open http://localhost/login.jsp time , tomcat had warned :   
     
  
life and death that can not find this action userLogin  

jsp file :

------ Solution -------------------- ------------------------
do not use a relative path because you start to go in and do not in this namespace , so coupled with engineering name , becomes absolutely Road King , you can access to !
------ For reference only -------------------------------------- -
namespace = "/" after such a change , or
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userLogin] associated with context path ; [ ] .
This error
------ For reference only -------------------------------- -------
namespace = "/ demo"

jsp file :


tomcat there is a warning :


how configuration changes the feeling did not work ? I had a tomcat restart

looked Html generated inside is this:

submitted to the url is http://localhost/userLogin, or given:
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userLogin] associated with context path ; [ ] .

not labels, with
submitted to the url is http://localhost/demo/userLogin.action, error message :
HTTP Status 404 - There is no Action mapped for action name userLogin.
------ For reference only ------- --------------------------------


with this configuration ?
I replaced this configuration

open http://localhost/login.jsp time , tomcat had warned :


life and death that can not find userLogin this action
------ For reference only -------------------------- -------------
problem solving, original bulid directory of classes directory to put the WEB-INF directory . .
Thank you

没有评论:

发表评论