File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble setting bean values in jsp via servlet in request scope

 
Harshvardhan gupta
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Harshvardhan gupta
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic