|
|
Error 404 in all my forms
Hi everyone. i have just begun learning this wonderful framework that is spring and i'm already stuck with a weird problem in all the forms that i have created i face the same problem when i push the submit button i have an error 404.
Here is one of the examples:
the dispatcher:
Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot; xmlns:xsi=quot;2001/XMLSchema-instancequot; xmlns:p=quot;schema/pquot; xmlns:aop=quot;schema/aopquot; xmlns:tx=quot;schema/txquot; xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans-2.5.xsd schema/aop schema/aop/spring-aop-2.5.xsd
schema/tx schema/tx/spring-tx-2.5.xsdquot;gt; lt;bean name=quot;/voiture.htmquot; class=quot;springapp.web.CouleurControllerquot;gt; lt;property name=quot;commandNamequot; value=quot;voitquot;/gt; lt;property name=quot;commandClassquot; value=quot;springapp.model.Voiturequot;/gt; lt;property name=quot;validatorquot;gt;lt;bean class=quot;springapp.service.VoitureValidatorquot;/gt; lt;/propertygt; lt;property name=quot;formViewquot; value=quot;saisiequot;/gt; lt;/beangt;
lt;bean id=quot;viewResolverquot; class=quot;org..web.servlet.view.InternalResourceViewResolverquot;gt; lt;property name=quot;viewClassquot; value=quot;org..web.servlet.view.JstlViewquot;/gt; lt;property name=quot;prefixquot; value=quot;/WEB-INF/jsp/quot;/gt; lt;property name=quot;suffixquot; value=quot;.jspquot;/gt; lt;/beangt; lt;!-- Most controllers will use the ControllerClassNameHandlerMapping above, but for the index controller we are using ParameterizableViewController, so we must define an explicit mapping for it. --gt;
lt;/beansgt;
the contoller:
Code:
/** To change this template, choose Tools | Templates* and open the template in the editor.*/
package springapp.web;
/**** @author hamza*/
import org..web.servlet.mvc.SimpleFormController;
import org..web.servlet.ModelAndView;
import org..web.servlet.view.RedirectView;
import javax.servlet.ServletException;
import javax.servlet.from.fromServletRequest;
import springapp.model.Voiture;
public class CouleurController extends SimpleFormController {
/** Logger for this class and subclasses */
@Override public ModelAndView onSubmit(Object command)throws ServletException {
return new ModelAndView(quot;indexquot;); }
@Override protected Object formBackingObject(fromServletRequest request) throws ServletException { Voiture voit = new Voiture(); return voit; }
}
the form:
Code:
lt;%@ taglib prefix=quot;formquot; uri=quot;tags/formquot; %gt;
lt;htmlgt;
lt;headgt; lt;titlegt;lt;fmt:message key=quot;titlequot;/gt;lt;/titlegt; lt;stylegt; .error { color: red; } lt;/stylegt;
lt;/headgt;
lt;bodygt;
lt;form:form method=quot;postquot; commandName=quot;voitquot;gt; lt;table width=quot;95%quot; bgcolor=quot;f8f8ffquot; border=quot;0quot; cellspacing=quot;0quot; cellpadding=quot;5quot;gt; lt;trgt; lt;td align=quot;rightquot; width=quot;20%quot;gt;couleur:lt;/tdgt; lt;td width=quot;20%quot;gt; lt;form:input path=quot;couleurquot;/gt; lt;/tdgt; lt;td width=quot;60%quot;gt; lt;form:errors path=quot;couleurquot; cssClass=quot;errorquot;/gt; lt;/tdgt; lt;/trgt; lt;/tablegt; lt;brgt; lt;input type=quot;submitquot; align=quot;centerquot; value=quot;Executequot;gt;
lt;/form:formgt;
lt;/bodygt;
lt;/htmlgt;
this just a remarque the ucl of the form is voiture.htm but when i click on the button i have /WEB-INF/jsp/saisie.jsp.And also i have a question about the commandName attribute its use is just like a object that you pass that you have to specify in the dispatcher file with it's type?
sorry if my english is bad i am moroccan so please just bear with me.
i fixed this problem just by moving the jso from WEB-INF to the root directory but i have a new problem i have a Neither BindingResult nor plain target object for bean name quot;voitquot;. if someone know the solution please let me know.
united4life,
Try adding a ucl mapping bean in your servlet context, like:Code: lt;!-- no 'id' required, HandlerMapping beans are automatically detected by the DispatcherServlet --gt; lt;bean class=quot;org..web.servlet.handler.BeanNameuclHandlerMappingquot;/gt;
and moving your jsp files back to the WEB-INF directory.
By not placing them there, they aren't managed by Spring, thus the command object (or errors, etc) aren't injected into the request context for viewing as the servlet container is serving them directly.
Also, make sure you have the correct servlet-mapping in your web.xml
Hope that helps.
jpreston thank you for your reply,
i did what you suggested but the problem still persists, But i have found an alternative solution that works fine.I moved back the jsp folder to WEB-INF and i have changed the jsp like that:
Code:
lt;%@ include file=quot;/jsp/include.jspquot; %gt;
lt;%@ taglib prefix=quot;formquot; uri=quot;tags/formquot; %gt;
lt;%@ taglib prefix=quot;springquot; uri=quot;/springquot; %gt;
lt;htmlgt;
lt;headgt; lt;titlegt;lt;fmt:message key=quot;titlequot;/gt;lt;/titlegt; lt;stylegt; .error { color: red; } lt;/stylegt;
lt;/headgt;
lt;bodygt;
lt;h1gt;lt;fmt:message key=quot;priceincrease.headingquot;/gt;lt;/h1gt;
lt;form method=quot;postquot; gt; lt;table width=quot;95%quot; bgcolor=quot;f8f8ffquot; border=quot;0quot; cellspacing=quot;0quot; cellpadding=quot;5quot;gt; lt;trgt; lt;td align=quot;rightquot; width=quot;20%quot;gt;Increase (%):lt;/tdgt; lt;td width=quot;20%quot;gt;lt;spring:bind path=quot;priceIncrease.percentagequot; gt; lt;input type=quot;textquot; name=quot;percentagequot; /gt; lt;tdgt; lt;font color=quot;redquot;gt; lt;bgt;lt;c ut value=quot;${status.errorMessage}quot;/gt;lt;/bgt; lt;/fontgt; lt;/tdgt;lt;/spring:bindgt; lt;/tdgt; lt;td width=quot;60%quot;gt; lt;/tdgt; lt;/trgt; lt;/tablegt; lt;brgt; lt;input type=quot;submitquot; align=quot;centerquot; value=quot;Executequot;gt;
lt;/formgt;
lt;a hrcf=quot;lt;c:ucl value=quot;hello.htmquot;/gt;quot;gt;Homelt;/agt;
lt;/bodygt;
lt;/htmlgt;
and when i try the old jsp i have the 404 problem after submiting the form. |
|