File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes  nested exception is org.xml.sax.SAXParseException: Attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark " nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared" Watch " nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared" New topic
Author

nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared

Tulip Jain
Greenhorn

Joined: Nov 08, 2011
Posts: 13
Hi Guys... i m new to this Spring framework....

I m facing this ERROR nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared for element type "property".

Please help me out ... in my spring-servlet.xml ...

My spring-servlet.xml is :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


<!-- Maps flow requests from DispatcherServlet to flowController -->

<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/index.html=loginController
</value>
</property>
</bean>

<!-- Mappings required for the loginFormController are-->

<bean id="loginConroller" class="loginFormController">
<property name="commandName" value="login"></property>
<property name="commandClass" value="Login"></property>
<property name="formView"><value>index</value></property>
<property name="successView"><value>success</value></property>
</bean>



<!-- Maps a logical view name to a physical resource -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>

</beans>


& my controller class is:

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class loginFormController extends SimpleFormController {

@Override
protected ModelAndView onSubmit(Object command) throws Exception {

Login log=(Login)command;

String uname=log.getUsername();

ModelAndView mav= new ModelAndView(getSuccessView());

mav.addObject("uname",uname);
//Add an object to the model.
//modelName - name of the object to add to the model
//modelObject - object to add to the model. May not be null.

return mav;
}

}

Appreciate your response----
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

The error message says that your "property" element must have a "value" attribute. But in your example:

it doesn't have a "value" attribute. (Which is of course exactly what the error message says.)

You might want to spend a couple of minutes learning about XML, in particular what does the term "attribute" mean in XML.
Tulip Jain
Greenhorn

Joined: Nov 08, 2011
Posts: 13
Thanks Paul for your reply ....

i forgot to mention that the error is in the below "value" tag....

<bean id="loginConroller" class="loginFormController">
line 20 <property name="commandName" value="login"></property>
<property name="commandClass" value="Login"></property>
<property name="formView"><value>index</value></property>
<property name="successView"><value>success</value></property>
</bean>

for ease, here is the actual error .....

org.springframework.beans.factory.BeanDefinitionStoreException: Line 20 in XML document from ServletContext resource [/WEB-INF/polling-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared for element type "property".
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:135)
org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:144)
org.springframework.context.support.AbstractXmlApplicationContext.refreshBeanFactory(AbstractXmlApplicationContext.java:79)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:249)
org.springframework.web.context.support.XmlWebApplicationContext.refresh(XmlWebApplicationContext.java:131)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:281)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:228)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:199)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:103)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:722)


Thanks ....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

I would be more likely to believe that the error referred to the lines just below, which in fact do not have "value" attributes. I suggest that if you fix the lines which don't have "value" attributes then you won't get error messages. But pointing at a document which obviously does have errors and saying that the error message doesn't apply because it appears to point at one line which doesn't have an error, that's just wasting time. Fix the errors already.
Tulip Jain
Greenhorn

Joined: Nov 08, 2011
Posts: 13
Thnaks for the guidance Paul ... I will try to fix this out ....
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

Both the nested <value> node or the "value" attribute are valid formats supported by Spring.
http://static.springsource.org/spring/docs/2.0.x/reference/beans.html#beans-value-element


My suspect would be the line breaks between the value attributes in this bean



I also suggest using the XSD schema instead of the doctype.


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Tulip Jain
Greenhorn

Joined: Nov 08, 2011
Posts: 13
Thanks Everyone Guys

error was resolved actually there were 2 problem one was in the jar files.... i was using 2 versions of a same jar files ..... when i replaced it by using common-logging.jar. jstl.jar, spring.jar & standard.jar files in my lib folder it worked...

Also when i replaced the following the code

<bean id="loginConroller" class="loginFormController">
<property name="commandName" value="login"></property>
<property name="commandClass" value="Login"></property>

<property name="formView"><value>index</value></property>
<property name="successView"><value>success</value></property>
</bean>

<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>


by-


<property name="commandName"><value>login</value></property>
<property name="commandClass"><value>Login</value></property>

<property name="prefix"><value>/WEB-INF/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>


IT WORKED..... dont know wats d problem!!!... in my opinion both are valid formart in spring....!!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

Sam Mercs wrote:Both the nested <value> node or the "value" attribute are valid formats supported by Spring.


In which case the error message (which explicitly says that an attribute is missing) is seriously misleading.
Tulip Jain
Greenhorn

Joined: Nov 08, 2011
Posts: 13
Ya... very true .....its very hard to find....
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

Paul Clapham wrote:
Sam Mercs wrote:Both the nested <value> node or the "value" attribute are valid formats supported by Spring.


In which case the error message (which explicitly says that an attribute is missing) is seriously misleading.


I know the format is supported in 2.5 version onwards, not so sure about Spring 2.0. Maybe it's not supported in those jars which is why that particular message shows up. Wrong jar issues (class path issues) are hard to debug but doesn't mean that message is really misleading ...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

Just to clarify: I meant to say that I would interpret that message about an "attribute" which wasn't declared to mean that an XML attribute was necessary. That would imply to me that a child element -- which is not an attribute in XML -- is unacceptable. It's bad enough that we have people working with XML who haven't even read the one-page summary and who don't know what an attribute is (not you, I hasten to say), we don't need people writing error messages which muddy the waters.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared