spring入门几个问题及解决

来源:chinaunix博客 作者:佚名 2008-04-16 出处:pcdog.com

apache  java  jsp  spring  xml  
下一页 1 2 

1.<bean id="helloWorld" class="org.andyny.action.HelloWorld">
      <constructor-arg index="0"> //注意: index="引号+数字"
      <value>hi,hahahaha</value>

      </constructor-arg>
      </bean>


    2.spring配置文件
    applicationContext.xml配置文件放在本项目的工作目录下,即是:springMVC应用程序下。或者Web项目的WEB-INF目录下


    3.web.xml,config.xml等各配置文件中,若批处理命令中参数(如:web-app 2.2/web-app 2.4版本不匹配问题及encoding编码与平台的默认编码不符合问题)
    都会显示错误。


    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">


    4.java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener
     registered?
     at
     org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestC
     o
     ntextUtils.java:84)
     at
     org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:206)
     at
     org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestCon
     t
    ............


    解决办法:
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/applicationContext.xml
    </param-value>
    </context-param>

    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>

    将上述的代码添加到web.xml文件,注意是:<servlet>标签之前。


    5.配置taglib


    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app 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"
        version="2.4">

        <jsp-config> // 注意:此版本需要<jsp-config>, web-app_2_2.xsd则不要。
           <taglib>
         <taglib-uri>
            /spring
         </taglib-uri>
         <taglib-location>
           /WEB-INF/spring.tld
         </taglib-location>
     </taglib>
           </jsp-config>


    6.ListIterator

     注意:void remove()
              从迭代器指向的 collection 中移除迭代器返回的最后一个元素(可选操作)。

       Iterator和ListIterator的不同使用方法


    我们在使用List,Set的时候,为了实现对其数据的遍历,我们经常使用到了Iterator(跌代器)。使用跌代器,你不
    需要干涉其遍历的过程,只需要每次取出一个你想要的数据进行处理就可以了。

    但是在使用的时候也是有不同的。List和Set都有iterator()来取得其迭代器。对List来说,你也可以通过
    listIterator()取得其迭代器,两种迭代器在有些时候是不能通用的,Iterator和ListIterator主要区别在以下方
    面:


更多内容请看PCdog.com--Spring开发技术篇  电脑入门教程专题
下一页 1 2 
上一篇:Java 学习笔记:泛型(一)
下一篇:Dojo 之 面向对象