J2EE社區(qū)

          茍有恒,何必三更起五更眠;
          最無益,只怕一日曝十日寒.
          posts - 241, comments - 318, trackbacks - 0, articles - 16
          web.xml
              

          <?xml version="1.0" encoding="UTF-8"?>
          <web-app version="2.5" 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_2_5.xsd">
           <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
           </welcome-file-list>

           <!-- Standard Action Servlet Configuration -->
           <servlet>
            <servlet-name>action</servlet-name>
            <servlet-class>
             org.apache.struts.action.ActionServlet
            </servlet-class>
            <init-param>
             <param-name>config</param-name>
             <param-value>/WEB-INF/struts-config.xml</param-value>
            </init-param>
            <load-on-startup>2</load-on-startup>
           </servlet>


           <!-- Standard Action Servlet Mapping -->
           <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
           </servlet-mapping>
          </web-app>




          struts-config.xml

          <?xml version="1.0" encoding="ISO-8859-1" ?>

          <!DOCTYPE struts-config PUBLIC
                    "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
                    "http://struts.apache.org/dtds/struts-config_1_3.dtd">

          <struts-config>

           <form-beans>
            <form-bean name="loginForm" type="com.test.user.web.forms.LoginActionForm"/>
           </form-beans>
            
              <global-forwards>
            <forward name="success" path="/success.jsp"/>
              </global-forwards>
              
              <action-mappings>
               <action path="/loginPage" forward="/login.jsp"></action>
               <action path="/login" type="org.springframework.web.struts.DelegatingActionProxy" name="loginForm" scope="request" />
              </action-mappings>
              <message-resources parameter="MessageResources" />
           
          </struts-config>




          applicationContext-beans.xml 

          <?xml version="1.0" encoding="UTF-8"?>

          <!--
            - Application context definition for JPetStore's business layer.
            - Contains bean references to the transaction manager and to the DAOs in
            - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
            -->
          <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
           
           <bean id="userManager" class="com.test.user.web.manager.UserManagerImpl" />

          </beans>



          applicationContext-actions.xml

          <?xml version="1.0" encoding="UTF-8"?>

          <!--
            - Application context definition for JPetStore's business layer.
            - Contains bean references to the transaction manager and to the DAOs in
            - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
            -->
          <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
           
            <bean name="/login" class="com.test.user.web.actions.LoginAction">
            <property name="userManager">
             <ref bean="userManager"/>
            </property>
           </bean>

          </beans>



          ActionFrom

          package com.test.user.web.forms;

          import javax.servlet.http.HttpServletRequest;

          import org.apache.struts.action.ActionErrors;
          import org.apache.struts.action.ActionForm;
          import org.apache.struts.action.ActionMapping;
          import org.apache.struts.action.ActionMessage;

          public class LoginActionForm extends ActionForm
          {

           /**
            *
            */
           private static final long serialVersionUID = 1L;
           private String username;
           private String password;
           public String getUsername()
           {
            return username;
           }
           public void setUsername(String username)
           {
            this.username = username;
           }
           public String getPassword()
           {
            return password;
           }
           public void setPassword(String password)
           {
            this.password = password;
           }
           @Override
           public void reset(ActionMapping mapping, HttpServletRequest request)
           {
            this.username = null;
            this.password = null;
           }
           @Override
           public ActionErrors validate(ActionMapping mapping,
             HttpServletRequest request)
           {
            ActionErrors messages = new ActionErrors();
            if(this.username == null || this.password == null)
             messages.add("username", new ActionMessage("用戶名或者密碼不能為空"));
            return messages;
           }
           
           
          }



          Action:

          package com.test.user.web.actions;

          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          import org.apache.struts.action.Action;
          import org.apache.struts.action.ActionForm;
          import org.apache.struts.action.ActionForward;
          import org.apache.struts.action.ActionMapping;

          import com.test.user.web.forms.LoginActionForm;
          import com.test.user.web.manager.UserManager;

          public class LoginAction extends Action
          {
           private UserManager userManager;
           public void setUserManager(UserManager userManager)
           {
            this.userManager = userManager;
           }
           @Override
           public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws Exception
           {
            LoginActionForm loginForm = (LoginActionForm)form;
            
            String username = loginForm.getUsername();
            String password = loginForm.getPassword();
            
            userManager.login(username, password);
            
            return mapping.findForward("success");
           }
           
          }



          manager:

          package com.test.user.web.manager;


          public class UserManagerImpl implements UserManager
          {

           @Override
           public void login(String username, String password)
           {
            System.out.println("在這可以再設(shè)置一個dao,然后結(jié)合hibernate操作數(shù)據(jù)庫");
           }

          }


           



          運行結(jié)果報錯:
          java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
          org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext
          org.springframework.web.struts.DelegatingActionUtils.findRequiredWebApplicationContext(java:148)
          org.springframework.web.struts.DelegatingActionProxy.getWebApplicationContext(java:139)
          org.springframework.web.struts.DelegatingActionProxy.getDelegateAction(DelegatingActionProxy.java:120)
          org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)
          org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
          org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
          org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
          org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
          org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
          org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
          org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
          org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
          org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          



          名稱: ?4C.ESL | .↗Evon
          口號: 遇到新問題?先要尋找一個方案乄而不是創(chuàng)造一個方案こ
          mail: 聯(lián)系我


          Feedback

          # re: javax.servlet.ServletException: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered錯誤  回復(fù)  更多評論   

          2008-08-09 20:57 by xcp
          怎么沒得高手回呢,小弟在線等你們```````

          # re: javax.servlet.ServletException: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered錯誤[未登錄]  回復(fù)  更多評論   

          2008-08-09 21:23 by chinajj
          web.xml 里面加入
          <listener>
          <listener-class>
          org.springframework.web.context.ContextLoaderListener
          </listener-class>
          </listener>

          # re: javax.servlet.ServletException: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered錯誤  回復(fù)  更多評論   

          2008-08-09 22:38 by BeanSoft
          或者在這里:MyEclipse 5.5 開發(fā) Spring + Struts + Hibernate 的詳解視頻http://www.aygfsteel.com/beansoft/archive/2007/10/07/150877.html

          Spring 整合 Struts
          ? 添加 Spring Plug in
          Ø <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
          Ø <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
          Ø </plug-in>
          ? 替換 Action 的 Type
          Ø <action path="/login“ …
          Ø type="org.springframework.web.struts.DelegatingActionProxy" />
          ? 在 Spring 配置文件中配置 Bean
          Ø 要點: 通過 path 和 bean 的 name 進(jìn)行匹配, 這兩個值必須一樣
          Ø <bean name="/login" class="com.test.struts.action.LoginAction"></bean>

          # re: javax.servlet.ServletException: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered錯誤  回復(fù)  更多評論   

          2008-08-09 22:48 by zbh
          看 劉長炯的視頻!!

          # re: javax.servlet.ServletException: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered錯誤  回復(fù)  更多評論   

          2008-08-10 10:04 by xcp
          好,謝謝各位了,問題解決了,方法如下:

          方法一:
          第一:發(fā)現(xiàn)原來是他的配置文件不是放在WEB-INF下,而是放在src目錄下,解決的方法可將其spring的配置文件applicationContext轉(zhuǎn)移陣地,轉(zhuǎn)到WEB-INF下,或在web.xml下加入如下語句:
          <!-- Spring ApplicationContext配置文件的路徑,可使用通配符,多個路徑用,號分隔此參數(shù)用于后面的Spring-Context loader -->

          <context-param>

          <param-name>contextConfigLocation</param-name>

          <param-value>/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml</param-value>

          </context-param>

          第二:在web.xml里面加上樓上說的
          <listener>
          <listener-class>
          org.springframework.web.context.ContextLoaderListener
          </listener-class>
          </listener>



          方法二:就是樓上BeanSoft所說的加上一個plugin就可以了,但是值得注意的是上面的contextConfigLocation屬性名是不可變的,而這個路徑主要是看項目中spring配置文件放置地點..


          在這謝謝各位哈!!

          # re: javax.servlet.ServletException: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered錯誤  回復(fù)  更多評論   

          2008-12-18 15:59 by snidt
          配置插件
          主站蜘蛛池模板: 玉龙| 五台县| 凤阳县| 平舆县| 玉树县| 波密县| 桐庐县| 尼玛县| 奎屯市| 抚远县| 襄樊市| 驻马店市| 米林县| 土默特左旗| 孟津县| 老河口市| 株洲市| 安庆市| 秭归县| 渑池县| 敦化市| 安徽省| 慈溪市| 贡山| 辽阳县| 长葛市| 台南市| 水富县| 蒙阴县| 平邑县| 镇雄县| 青岛市| 丹巴县| 勃利县| 南雄市| 江津市| 永川市| 红原县| 华坪县| 井研县| 大姚县|