论坛首页 Java企业应用论坛

问一下<sping:bind>的错误

浏览 11071 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-04-06  
tomcat5.08
jdk1.4.2

当我不用<spingbind>标签时候
一切正常
但是用了<spingbind>后,提示
java.lang.IllegalStateException No WebApplicationContext found no ContextLoaderListener registered?
org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java82)
org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java203)
org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java74)
org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java48)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java67)
org.apache.jsp.form_jsp._jspService(form_jsp.java70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java94)
javax.servlet.http.HttpServlet.service(HttpServlet.java802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java236)
javax.servlet.http.HttpServlet.service(HttpServlet.java802)

能不能请知情人讲解一下
这是两个jsp文件
第一个正确,可以执行
<%@page contentType="text/html;charset=gb2312"%>
<html>
<head><title>Login</title></head>
<body>
        <form name="loginform" action="/springapp/login.do" method="post">
        username <input type="text" name="username"/><br>
     passweord <input type="password" name="password"/><br>
        <input type="submit" value="確定"/>
    </form>
   </body>
</html>


这是出错的页面
<%@page contentType="text/html;charset=gb2312"%>
<%@taglib prefix="spring" uri="/spring"%>
<html>
<head><title>Login</title></head>
<body>
    <springbind path="command.*">
        <font color="red"><b>${status.errorMessage}</b></font><br>
    </springbind>
   
    请输入用户名和密码:<p>
    <form name="loginform" action="/springapp/login.do" method="post">
   
        <springbind path="command.username">
        用户名 <input type="text" name="${status.expression}" value="${status.value}"/><br>
        </springbind>
   
        <springbind path="command.password">
        密码 <input type="password" name="${status.expression}" value="${status.value}"/><br>
        </springbind>
   
        <input type="submit" value="确定"/>
    </form>
</body>
</html>
   发表时间:2005-04-06  
只是加了一个<sping:bind>
就提示了这个错误

别的配置文件应该没有错误
0 请登录后投票
   发表时间:2005-04-07  
你是否用了spring的 dispatcher 转到页面呢?

如果是的话,应该没有这个错误的.

这个错误是因为没有获得spring的context而出错.
0 请登录后投票
   发表时间:2005-04-07  
把你的xml发上来!你的配置一定有问题。
0 请登录后投票
   发表时间:2005-04-07  
把web.xml贴出来
0 请登录后投票
   发表时间:2005-04-07  
这是web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http//java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
<servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>
      index.jsp
    </welcome-file>
  </welcome-file-list>
 
  <taglib>
    <taglib-uri>/spring</taglib-uri>
    <taglib-location>/WEB-INF/spring.tld</taglib-location>
  </taglib>
</web-app>

这是spring的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http//www.springframework.org/dtd/spring-beans.dtd">
<beans>    
    <bean id="helloUserAction" class="web.HelloUserAction">
        <property name="helloWord">
            <value>Hello!</value>
        </property>
        <property name="viewPage">
             <value>hellouser</value> 
        </property>
    </bean>           

    <bean id="loginAction" class="web.LoginAction">
        <property name="commandClass">
            <value>bus.LoginForm</value>
        </property>
        <property name="successView">
            <value>success</value>
        </property>
        <property name="formView">
            <value>form</value>
        </property>
    </bean>   

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename"><value>messages</value></property>
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>                       
                <prop key="/hellouser.do">helloUserAction</prop>
                <prop key="/login.do">loginAction</prop>               
            </props>
        </property>
    </bean>
   
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>
  
</beans>
0 请登录后投票
   发表时间:2005-04-07  
根据文档,你应该加上一个listener或servlet,将applicationContext注册到当前的Web环境中去。

3.18. Creating an ApplicationContext from a web application
As opposed to the BeanFactory, which will often be created programmatically, ApplicationContexts can be
created declaratively using for example a ContextLoader. Of course you can also create ApplicationContexts
programmatically using one of the ApplicationContext implementations. First, let's examine the ContextLoader
and its implementations.
The ContextLoader has two implementations: the ContextLoaderListener and the ContextLoaderServlet.
They both have the same functionality but differ in that the listener cannot be used in Servlet 2.2 compatible
containers. Since the Servlet 2.4 specification, listeners are required to initialize after startup of a web
application. A lot of 2.3 compatible containers already implement this feature. It is up to you as to which one
you use, but all things being equal you should probably prefer ContextLoaderListener; for more information
on compatibility, have a look at the JavaDoc for the ContextLoaderServlet.
You can register an ApplicationContext using the ContextLoaderListener as follows:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- OR USE THE CONTEXTLOADERSERVLET INSTEAD OF THE LISTENER
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
-->

The listener inspects the contextConfigLocation parameter. If it doesn't exist, it'll use
/WEB-INF/applicationContext.xml as a default. When it does exist, it'll separate the String using predefined
delimiters (comma, semi-colon and space) and use the values as locations where application contexts will be
searched for. The ContextLoaderServlet can - as said - be used instead of the ContextLoaderListener. The
servlet will use the contextConfigLocation parameter just as the listener does.
0 请登录后投票
   发表时间:2005-04-07  
我用的这个web和servlet的配置文件都是spring mvc step by step里的配置文件
它的这个jsp文件就可以用&lt;springbind&gt;,可是我的还是不能用

&lt;%@ include file="/WEB-INF/jsp/include.jsp" %&gt;
&lt;%@ taglib prefix="spring" uri="/spring" %&gt;

&lt;html&gt;
&lt;head&gt;&lt;title&gt;&lt;fmtmessage key="title"/&gt;&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;&lt;fmtmessage key="priceincrease.heading"/&gt;&lt;/h1&gt;
&lt;form method="post"&gt;
  &lt;table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5"&gt;
    &lt;tr&gt;
      &lt;td alignment="right" width="20%"&gt;Increase (%)&lt;/td&gt;
      &lt;springbind path="priceIncrease.percentage"&gt;
        &lt;td width="20%"&gt;
          &lt;input type="text" name="percentage" value="&lt;cout value="${status.value}"/&gt;"&gt;
        &lt;/td&gt;
        &lt;td width="60%"&gt;
          &lt;font color="red"&gt;&lt;cout value="${status.errorMessage}"/&gt;&lt;/font&gt;
        &lt;/td&gt;
      &lt;/springbind&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br&gt;
  &lt;springhasBindErrors name="priceIncrease"&gt;
    &lt;b&gt;Please fix all errors!&lt;/b&gt;
  &lt;/springhasBindErrors&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;input type="submit" alignment="center" value="Execute"&gt;
&lt;/form&gt;
&lt;a href="&lt;curl value="hello.htm"/&gt;"&gt;Home&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
0 请登录后投票
   发表时间:2005-04-07  
试过了
还是不行啊?
哪位有简单的用户登陆的例子

能不能给我参考一下
0 请登录后投票
   发表时间:2005-04-07  
你在web.xml中加了hunte的配置吗?
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics