Solved

URGENT: Get a parameter through the request of the onSubmit() method

Posted on 2009-05-18
38
2,001 Views
Last Modified: 2013-11-11
Hi,
I am passing a parameter from a SimpleFormController to another SimpleFormController and i don't know why i cannot get it by the request of the onSubmit() method. The code will help you understand what i m trying to say
This is the first SimpleFormController that passes the parameter:
 
public class LoginController extends SimpleFormController
{
    public LoginController() 
    {   
    }
 
    private RSSUserService rssUserService;
    
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, 
                                    BindException bindException) throws Exception 
    {
        RSSUser rssUser = (RSSUser) command;
        List<RSSUser> rssUsers = getRssUserService().login();
        Integer userId = null;
        for (int i = 0; i < rssUsers.size(); i++) 
        {
            if (rssUsers.get(i).getUsername().equals(rssUser.getUsername()) && rssUsers.get(i).getPassword().equals(rssUser.getPassword())) 
            {
                userId = rssUsers.get(i).getId();
            }
        }
        return new ModelAndView(getSuccessView(), "userId", userId);
    }
 
    public RSSUserService getRssUserService() {
        return rssUserService;
    }
 
    public void setRssUserService(RSSUserService rssUserService) {
        this.rssUserService = rssUserService;
    }
    
}
 
And the following controller is supposed to receive the parameter:
 
public class LoadRSSController extends SimpleFormController
{
    public LoadRSSController() 
    {
    }
         
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException exception) throws Exception 
    {
        RSS rssObject = (RSS) command;       
        String url = rssObject.getUrl();
        Element eRSS = getXmlParsingService().getElement(url); 
        String idStr = request.getParameter("userId");
        Integer id = null;
        if (!idStr.equals(null)) 
        {
            id = Integer.parseInt(idStr);
        }
        RSSUser rssUser = getRssUserService().getRssUserById(id);
        RSS rss = getRssService().loadRSS(eRSS, url, rssUser);
        getRssItemService().loadRSSItems(eRSS, rss);
        getRssImageService().loadRSSImage(eRSS, rss);
        return new ModelAndView(getSuccessView());
    }
 
But after debugging the result of the request.getParameter("userId") is always null.

Open in new window

0
Comment
Question by:nick0306
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 9
  • 4
  • +2
38 Comments
 
LVL 1

Expert Comment

by:rbrindl
ID: 24413691
Can you please supply the view?
If you are expecting the value come back to another controller, then the view (i.e. the html page) must supply the form and input tags so that the requestParameter is sent back to the other controller.

i.e. the jsp page (or similar) should contain something like:

<form:form>
           <form:input path="userId" />
</form:form>

where the path depends on your mapping.
0
 

Author Comment

by:nick0306
ID: 24413895
The view of the login page looks like:
............
<form:form commandName="rssUsers" method="POST" action="login.htm">
<form:input path="username" size="40px"/>
<form:password path="password" size="40px"/>
<input type="submit" value="LOGIN"></input>
<form:errors id="wrongCredentials" />
</form:form>
............

And the view of the LoadRSS page looks like:

............
<form:form commandName="loadRSS" method="POST" action="loadRSS.htm">
<form:input path="url" size="80px"/>
<input type="submit" value="SAVE"></input>
<form:errors id="required.url"/>
 </form:form>
...........

Bear in mind that both are simpleFormControllers and they have a different commandClass, the first has RSSUsers object for class and the second has the RSS object for class

Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 24417132
thats passing the userId to the view, not to the other controller
0
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 
LVL 1

Expert Comment

by:rbrindl
ID: 24418943
I don't know if i am missing something here, but as far as i understand, the view should hold a field with name userID, so you can get it with request.getParameter. I don't see such a field in your views.

@objects: yes, it is passing it to the view, and the view passes it to the other controller. At least that's how i understand it.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24419086
use

String idStr = request.getAttribute("userId");
instead of
String idStr = request.getParameter("userId");

remember once the request is created, you cant change the parameters in it, but you send around attributes associated with your request, thats what struts, or spring or other most framework use to send things around.
0
 

Author Comment

by:nick0306
ID: 24419514
Okay, the getAttribute is not working, and i tried to catch the parameter in the view but still is not working.
I changed the view of the loadRSS to:

.....................
 <c:catch var="userId" />
<form:form commandName="loadRSS" method="POST" action="loadRSS.htm">
<form:input path="url" size="80px"/>
<input type="submit" value="SAVE"></input>
<form:errors id="required.url"/>
 </form:form>
........................

and then in the controller: String idStr = request.getParameter("userId")
but i cannot understand how my variable in the jsp and from where will get its value..
0
 
LVL 92

Expert Comment

by:objects
ID: 24419532
its being passed to the success view of your login controller
are you passing it from that page to the load controller?

0
 

Author Comment

by:nick0306
ID: 24419557
Yes, i pass it from the login controller (getSuccessView(), "userId", userId) (btw successView = redirect to loadRSS) and then i catch it in my loadRSS.jsp like : <c:catch var="userId" />
and then in the loadRSSController when the onSubmit is called i get it like: String idStr = request.getParameter("userId");

Results:
Debugging shows that the parameter is passed alright but in the loadRSSController i get no value.
I don't know how to check my jsp if getting it
0
 

Author Comment

by:nick0306
ID: 24419565
Btw i tried to create a session in the login controller:
HttpSession session = request.getSession(true)
session.setAttribute("userId", userId);

And then get it from the loadRSSController:
request.getSession().getAttribute("userId");

but still doesn't work....

and to be honest i would prefer to have it in a session from which every controller of mine would have access
0
 
LVL 92

Expert Comment

by:objects
ID: 24419677
the map won't be passed in a redirect

not sure why the session isn't working, have you checked it is the same session

0
 

Author Comment

by:nick0306
ID: 24419736
No it's the first time i use spring mvc and i m a bit lost...
Can you please tell me how to check if it is the same?
0
 
LVL 92

Expert Comment

by:objects
ID: 24419753
check the session id session.getId()
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24419767
so if I understand it correctly..

your flow is
loginpage--> loginpage controller--> RSSpage--> RSScontroller.

there is one user id which you get hold of in Logincontroller and want to use it later in RSScontroller...

If that is the senario, your session should have worked (provided you are in the same webapp)..

Also in order to the userId in RSSController.. you need to have that value available in your RSSPage as well..

another way of doing this will be to introduce the UserId in your RSS Bean and then using

<form:input path="userId" />

on your RSSPage..

Also do one test to see if your userId is reaching to your RSSPage ( here I am assuming that RSSPage is the successview of login)..

add
<c:out value="${userId}"/>

& see if the user id is printed there
0
 

Author Comment

by:nick0306
ID: 24419837
No it is a different session id... the think is in the loadRSSController i use this line of code in the onSubmit() method: String idStr = (String) request.getSession().getAttribute("userId");
and i am not sure if it is the way to get the session we created in the login controller.
0
 

Author Comment

by:nick0306
ID: 24419850
Yes my flow is like that but i didn't really understood what exactly to do... My loadRSS bean has a command class of rss object and cannot enter the rss user object...
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24420140
Did you try the last item of my post?

i.e. putting the <c:out on your rss page?
0
 

Author Comment

by:nick0306
ID: 24420147
Just a simple question:  I create a session called session in the login controller and i put an attribute in it.
        HttpSession session = request.getSession(true);
        session.setAttribute("userId", userId);

How do i get access to that session and to its attributes from any other SimpleFormController in this web app?
0
 

Author Comment

by:nick0306
ID: 24420177
i tried now.. it stucks... it doesn't forward to the loadRSS when i submit from my login page...
The code is :
Login controller:
return new ModelAndView(getSuccessView(), "userId", userId); (which has a value is already tested)

LoadRSS.jsp:
......
 <c:catch var="userId" />
  <c:out value="${userId}" />
  <form:form commandName="loadRSS" method="POST" action="loadRSS.htm">
     URL: <form:input path="url" size="80px"/> <input type="submit" value="SAVE"></input> <form:errors id="required.url"/>
     <br></br>
    <a href='<c:url value="listRSSFeeds.htm"/>'>LIST ALL RSS FEEDS</a>
    <p class="one" align="center"><a href='<c:url value="logout.htm"/>'>Log out</a>
  </form:form>
  </body>
......

LoadRSS Controller:
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException exception) throws Exception
    {
        RSS rssObject = (RSS) command;      
        String url = rssObject.getUrl();
        Element eRSS = getXmlParsingService().getElement(url);
        String idStr = (String) request.getParameter("userId");
        Integer id = null;
        if (!idStr.equals(null))
        {
            id = Integer.parseInt(idStr);
        }
        RSSUser rssUser = getRssUserService().getRssUserById(id);
        RSS rss = getRssService().loadRSS(eRSS, url, rssUser);
..........................
0
 

Author Comment

by:nick0306
ID: 24420350
Sorry it was stucking because of a stupid test i did....
The code i wrote above doesn't print any value....
0
 
LVL 1

Expert Comment

by:rbrindl
ID: 24420404
As i said before:
Want to get a parameter from a HTTP Request, that parameter needs to be present in that request.
For that you need to submit it in the HTML Form, i.e.  you need some field with the name userId, that holds the value.
In you would do that with a <form:input path="userId"/>.
That way, the HTTP request will contain a Parameter with name userId, and Spring MVC will take care that the value gets populated from your login Controller. ( By the return new ModelAndView(getSuccessView(), "userId", userId);)
If you don't want the value to be displayed, use a hidden field.(form:hidden instead of form:input )

getSession(true) creates a new session each time, so you will not be able to see the attribute you set in the previous session.
If you want to get the current session associated with the current request, use getSession(), then the session attribute approach should work, too.
But i suggest not using sessions if not necessary, as it reduces scalability.


0
 

Author Comment

by:nick0306
ID: 24420506
Okay i did that... I get the following error:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userId' available as request attribute
I suspect is because the commandClass of the bean loadRSS is rss and not rssUser
0
 
LVL 1

Expert Comment

by:rbrindl
ID: 24420614
I am not a spring MVC specialist myself, only servlets and jsp. but please have a look at http://forum.springsource.org/archive/index.php/t-37068.html,
someone else is having the same issues.
It is about how spring handles models internally.
Please also see
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/servlet/mvc/AbstractFormController.html#workflow
and
http://static.springframework.org/spring/docs/2.5.x/reference/spring-form.tld.html#spring-form.tld.form

0
 

Author Comment

by:nick0306
ID: 24420635
ok i ll post any findings thnx
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24420695
In this code

<c:catch var="userId" />
  <c:out value="${userId}" />
  <form:form commandName="loadRSS" method="POST" action="loadRSS.htm">
     URL: <form:input path="url" size="80px"/> <input type="submit" value="SAVE"></input> <form:errors id="required.url"/>
     <br></br>
    <a href='<c:url value="listRSSFeeds.htm"/>'>LIST ALL RSS FEEDS</a>
    <p class="one" align="center"><a href='<c:url value="logout.htm"/>'>Log out</a>
  </form:form>
  </body>


remove the <c:catch var="userId" /> at the top, its declaring the variable and you will not see any value from c:out..

just use <c:out and let me know if it still comes as blank. ( it should not)
0
 

Author Comment

by:nick0306
ID: 24420748
I don't see anything in the page.. Is there another way to check its value?
0
 

Author Comment

by:nick0306
ID: 24420796
Something else which i find strange...
If i use handleRequestInternal() or formBackingObject() i can get the parameter from the request by using
request.getParameter("userId").
It's only the onSubmit() that does not get it...
And if i use handleRequestInternal then i cannot return a modelAndView without errors
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24420836
do right click view source and see if you see it there..


in spring when you send the model&view along with the name and object.. the jsp page def will have access to it..

so IF your logincontroller's success view is RSS page, I can see why you will not see the value of user id there..
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24420852
>>It's only the onSubmit() that does not get it...
And if i use handleRequestInternal then i cannot return a modelAndView without errors

its because onSumbit works with the commandbean that you have set up on your form.. until the variable is not there in the commandbean, you wont get to it.
0
 

Author Comment

by:nick0306
ID: 24420893
I saw the source and there is nothing there. It looks like i haven't entered the line:<c:out value.....

This is why i prefer to do it with a session so i can have access of that userId from all the controllers without the need to pass it all the time.
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 500 total points
ID: 24421029
implementing of the session should be working as long session is created once and used everywhere...

(i.e. using request.getSession(true)) at the start and then later on using request.getSession()....
I do not see a reason why it will not work unless there is something wrong\missing in spring config or setup files..
0
 

Author Comment

by:nick0306
ID: 24421051
probably yes.. what my config should include?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24421086
I will have to look at your spring-app.xml and web.xml to really see how they are looking right now..
0
 

Author Comment

by:nick0306
ID: 24421126
WEB XML :

<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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" xmlns="http://java.sun.com/xml/ns/j2ee">
    <description>RSS Web Application</description>
     <display-name>RSS Application</display-name>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/conf/rss-spring-services.xml
            /WEB-INF/conf/rss-spring-hibernate.xml
        </param-value>
    </context-param>
    <servlet>
        <description>Spring MVC Dispatcher Servlet</description>
        <servlet-name>MVCServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/conf/MVCServlet-servlet.xml</param-value>
          </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MVCServlet</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
    <session-config>
        <session-timeout>35</session-timeout>
    </session-config>
    <mime-mapping>
        <extension>html</extension>
        <mime-type>text/html</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>txt</extension>
        <mime-type>text/plain</mime-type>
    </mime-mapping>
</web-app>

AND THE SPRING IS DIVIDED INTO THREE FILES:

Spring hibernate:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
        <property name="url" value="jdbc:hsqldb:hsql://localhost/rss"/>
        <property name="username" value="sa"/>
        <property name="password" value=""/>
    </bean>
   
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
        <property name="dataSource" ref="dataSource" />
        <property name="mappingResources">
            <list>
                <value>com/nicolas/domain/RSS.hbm.xml</value>  
                <value>com/nicolas/domain/RSSItem.hbm.xml</value>
                <value>com/nicolas/domain/RSSImage.hbm.xml</value>
                <value>com/nicolas/domain/RSSUser.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties" >
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
   
    <bean id="rssDao" class=" com.nicolas.dao.hibernate.RSSHibernateDAO">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>  
   
    <bean id="rssItemDao" class=" com.nicolas.dao.hibernate.RSSItemHibernateDAO">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
   
    <bean id="rssImageDao" class=" com.nicolas.dao.hibernate.RSSImageHibernateDAO">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
   
    <bean id="rssUserDao" class=" com.nicolas.dao.hibernate.RSSUserHibernateDAO">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
   
     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
   
</beans>

Spring services:

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

<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.0.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
           
    <bean id="rssService" class=" com.nicolas.sevice.impl.RSSServiceImpl">
        <property name="rssDao" ref="rssDao"/>
    </bean>

    <bean id="rssItemService" class=" com.nicolas.sevice.impl.RSSItemServiceImpl">
        <property name="rssItemDao" ref="rssItemDao"/>
    </bean>
   
    <bean id="rssImageService" class=" com.nicolas.sevice.impl.RSSImageServiceImpl">
        <property name="rssImageDao" ref="rssImageDao"/>
    </bean>
   
    <bean id="rssUserService" class=" com.nicolas.sevice.impl.RSSUserServiceImpl">
        <property name="rssUserDao" ref="rssUserDao" />
    </bean>
   
    <bean id="xmlParsingService" class=" com.nicolas.sevice.impl.XMLParsingServiceImpl">
    </bean>
   
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" />
            <!--<tx:method name="*" propagation="SUPPORTS" read-only="true"/>-->
        </tx:attributes>
    </tx:advice>
   
    <aop:config>
        <aop:advisor
            pointcut="execution(* *..RSSService.*(..))"
            advice-ref="txAdvice" />
    </aop:config>
       
</beans>

and SpringMVCSerlvet:

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

<beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

  <bean id="messageSource" class=
      "org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
      <list>
        <value>messages</value>
        <value>errors</value>
      </list>
    </property>
  </bean>
 
    <bean id="urlMapping"
      class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
      <props>
        <prop key="/loadRSS.htm"> loadRSSController</prop>
        <prop key="/listRSSFeeds.htm">listRSSFeedsController</prop>
        <prop key="/listRSSItems.htm">listRSSItemsController</prop>
        <prop key="/editRSSItem.htm">editRSSItemController</prop>
        <prop key="/editRSS.htm">editRSSController</prop>
        <prop key="/deleteRSSItem.htm">deleteRSSItemController</prop>
        <prop key="/deleteRSSFeed.htm">deleteRSSFeedController</prop>
        <prop key="/login.htm">loginController</prop>
        <prop key="/register.htm">registerController</prop>
        <prop key="/logout.htm">logoutController</prop>
      </props>
    </property>
  </bean>
 
  <bean id="loadRSSValidator" class="com.nicolas.mvc.validators.LoadRSSValidator" />
 
  <bean id="editRSSItemValidator" class="com.nicolas.mvc.validators.EditRSSItemValidator" />
 
  <bean id="editRSSValidator" class="com.nicolas.mvc.validators.EditRSSValidator" />
 
  <bean id="loginValidator" class="com.nicolas.mvc.validators.LoginValidator" >
    <property name="rssUserService" ref="rssUserService" />
</bean>
 
  <bean id="registerValidator" class="com.nicolas.mvc.validators.RegisterValidator" >
     <property name="rssUserService" ref="rssUserService" />
</bean>
 
  <bean id="listRSSFeedsController"
      class="com.nicolas.mvc.ListRSSFeedsController">
    <property name="rssService" ref="rssService" />  
  </bean>
 
   <bean id="listRSSItemsController"
      class="com.nicolas.mvc.ListRSSItemsController">
    <property name="rssItemService" ref="rssItemService" />
    <property name="rssImageService" ref="rssImageService" />
  </bean>
 
  <bean id="editRSSItemController"
      class="com.nicolas.mvc.EditRSSItemController">
    <property name="formView" value="editRSSItem" />
    <property name="successView" value="redirect:listRSSItems.htm" />
    <property name="rssItemService" ref="rssItemService" />
    <property name="commandName" value="rssItem" />
    <property name="commandClass" value="com.nicolas.domain.RSSItem" />
    <property name="validator" ref="editRSSItemValidator"/>
  </bean>

    <bean id="editRSSController"
      class="com.nicolas.mvc.EditRSSController">
    <property name="formView" value="editRSS" />
    <property name="successView" value="redirect:listRSSFeeds.htm" />
    <property name="rssService" ref="rssService" />
    <property name="commandName" value="rss" />
    <property name="commandClass" value="com.nicolas.domain.RSS" />
    <property name="validator" ref="editRSSValidator" />
  </bean>
 
    <bean id="loadRSSController"
      class="com.nicolas.mvc.LoadRSSController">
    <property name="formView" value="loadRSS" />
    <property name="successView" value="redirect:listRSSFeeds.htm" />
    <property name="xmlParsingService" ref="xmlParsingService" />
    <property name="rssService" ref="rssService" />
    <property name="rssItemService" ref="rssItemService" />
    <property name="rssImageService" ref="rssImageService" />
    <property name="rssUserService" ref="rssUserService" />
    <property name="validator" ref="loadRSSValidator"/>
    <property name="commandName" value="loadRSS" />
    <property name="commandClass" value="com.nicolas.domain.RSS" />
    </bean>

    <bean id="deleteRSSItemController"
      class="com.nicolas.mvc.DeleteRSSItemController">
    <property name="rssItemService" ref="rssItemService" />
  </bean>

    <bean id="deleteRSSFeedController"
      class="com.nicolas.mvc.DeleteRSSFeedController">
    <property name="rssService" ref="rssService" />
    <property name="rssItemService" ref="rssItemService" />
    <property name="rssImageService" ref="rssImageService" />
  </bean>
 
  <bean id="loginController" class="com.nicolas.mvc.LoginController">
    <property name="rssUserService" ref="rssUserService" />
    <property name="formView" value="login" />
    <property name="successView" value="redirect:loadRSS.htm" />
    <property name="commandName" value="rssUsers" />
    <property name="commandClass" value="com.nicolas.domain.RSSUser" />
    <property name="validator" ref="loginValidator"/>
  </bean>
 
  <bean id="registerController" class="com.nicolas.mvc.RegisterController">
    <property name="rssUserService" ref="rssUserService" />
    <property name="formView" value="register" />
    <property name="successView" value="redirect:login.htm" />
    <property name="commandName" value="rssUsers" />
    <property name="commandClass" value="com.nicolas.domain.RSSUser" />
    <property name="validator" ref="registerValidator"/>
</bean>

<bean id="logoutController" class="com.nicolas.mvc.LogoutController">
</bean>

  <bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
  </bean>
 
</beans>

0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24422465
your xmls look alright, I dont see why a session will not work in this senario... tonight if I find time, I will try to see if I can work out a POC and see that the session is working as it should.
0
 

Author Comment

by:nick0306
ID: 24422630
thank you very much
0
 

Author Comment

by:nick0306
ID: 24426979
After all the code was correct but there is probably a problem with my pc's configuration as the session works fine in another computer. Thank you guys
0
 

Expert Comment

by:glimlach
ID: 24885737
Bug is in your code:
 for (int i = 0; i < rssUsers.size(); i++)
        {
            if (rssUsers.get(i).getUsername().equals(rssUser.getUsername()) && rssUsers.get(i).getPassword().equals(rssUser.getPassword()))
            {
                userId = rssUsers.get(i).getId();
            }
        }
        return new ModelAndView(getSuccessView(), "userId", userId);

There is no break after matching the username. so the next loop again assigning null.
0
 

Expert Comment

by:glimlach
ID: 24917868
Did you find the solution for your problem?
0

Featured Post

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question