aspose file tools*
The moose likes JSP and the fly likes Trouble setting bean values in jsp via servlet in request scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Trouble setting bean values in jsp via servlet in request scope" Watch "Trouble setting bean values in jsp via servlet in request scope" New topic
Author

Trouble setting bean values in jsp via servlet in request scope

Harshvardhan gupta
Greenhorn

Joined: Apr 04, 2010
Posts: 8

Hi i am trying to set my bean values from a html form (login.html) parameters into a jsp bean.the parameter from form first goes to a servlet named ELTest.java where i instantiate the bean and then bound that bean in request attribute and forward it to a jsp named first.jsp where bean value is supposed to be set using parameters.but the problem is when i output that value it shows null. please help me
here is jsp
--first.jsp--

<jsp:useBean id="Employee" type="com.example.model.Employee" scope="request" >
<jsp:setProperty name="Employee" property="ID"/>
</jsp:useBean>


<jsp:getProperty name="Employee" property="ID"/>


here is bean

--Employee.java--

package com.example.model;


public class Employee
{
private int ID;
public Employee(){}

public void setID(int ID)
{
this.ID=ID;
}
public int getID()
{
return ID;
}


}


here is servlet

--ELTest.java--

//
// ELTest.java
//
//
// Created by Harsh Gupta on 06/11/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
package com.example.web;

import javax.servlet.*;
import com.example.model.*;
import javax.servlet.http.*;
//import java.io.*;
//import java.util.*;

public class ELTest extends HttpServlet
{
String name,ID,name_ID;
//Map<String,String> musicMap =new HashMap<String,String>();
//ArrayList<String> myFood=new ArrayList<String>();
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
name=request.getParameter("name");
ID=request.getParameter("ID");
name_ID=name+ID;

if(name_ID!=null)
{

Employee e=new Employee();
request.setAttribute("Employee",e);
//request.setAttribute("User_info",name_ID);
request.getRequestDispatcher("first.jsp").forward(request,response);

}
}


}

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Can you please UseCodeTags for your source code, so that it becomes easier for people reading the query to follow the code.

Also please avoid using any instance variables in the Servlet like below:


Did you check if you are getting the correct parameters in the Servlet? You could try using a Debugger.


Mohamed Sanaulla | My Blog
Harshvardhan gupta
Greenhorn

Joined: Apr 04, 2010
Posts: 8
I am sorry for the mistakes mentioned by you.Actually i never posted anything before this in any of the forums so i have to learn a lot of etiquette . and yes i got the parameter values both in the servlet and in the jsp too (using param implicit object).But how to do it like the way i am trying to do.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble setting bean values in jsp via servlet in request scope