• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble setting bean values in jsp via servlet in request scope

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

}
}


}

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic