• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EL and jsp:usebean..type/class

Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two doubts...
1) In the code snippet shown in page 384 of HF, to get the request method,
it has been shown like pageContext.request.method which when called using a JSP shows like GET or POST. If i want to get a servlet initialization parameter from config, i used like pageContext.config.ininParam but the code threw error saying.. there is no property as config in tomcat 5.5.9. Where can i see the property like request in pageContext.request.method. I couldn't find that under javax.servlet.http.jsp. How can i get the init parameter for a jsp using config? Is that container implemented?

2) In the bullet points in page 414 of HF, the last but one shows that when jsp:useBean is used
along with jsp:setProperty only properties on type can only be set not the
property on class. Listed below are the classes

package com.utils;

public abstract class Person{
private String name;
public abstract void setName(String name);
public abstract String getName();

package com.utils;

public class Employee extends Person{
public Employee(){}
private String name;
private int empID;
private int age;
public void setName(String name)
public void setEmpID(int id)
public String getName()
{return name;}
public int getEmpID()
{return empID;}
public void setAge(int age)
public int getAge()
{return age;}

//The jsp with form
<form name="reqparamserv" method="Post" action="JSPStandardAct2.jsp">
Name: <input type="text" name="name" />
Employee ID:<input type="text" name="empID" />
<input type="submit" name="go" value="GO" />

//The jsp that sets the property
<jsp:useBean id="person" type="com.utils.Person" class="com.utils.Employee" scope="request" >
<jsp:setProperty name="person" property="name" param="name" />
<jsp:setProperty name="person" property="empID" param="empID" />
Person's name from servlet is:
<jsp:getProperty name="person" property="name" />
Person's ID from servlet is:
<jsp:getProperty name="person" property="empID" />

This page shows whatever i enter in the form like name and empID. I should be able to set the name only.
Pls. clarify. Thanks.
[ November 06, 2005: Message edited by: Kuppusamy Venkatasubramanian ]
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Venkatasubramanian,

Here are some clarifications to your doubts.

1. There is no map or bean object available for "servlet init" params. You need to pass init param name ("string" argument) to get init param value, but there is no mechanism available to pass argument on EL!

2. I got following servlet code on tomcat 5.5.7 version inside _jspService() method.

com.utils.Person person = null;
synchronized (request) {
person = (com.utils.Person) _jspx_page_context.getAttribute("person", PageContext.REQUEST_SCOPE);
if (person == null){
person = new com.utils.Employee();
_jspx_page_context.setAttribute("person", person, PageContext.REQUEST_SCOPE);
out.write(" ");
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person"), "name", request.getParameter("name"), request, "name", false);
out.write(" ");
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person"), "empID", request.getParameter("empID"), request, "empID", false);
out.write(" ");
out.write(" Person's name from servlet is: \n");
out.write(" ");
out.write(" <br>\n");
out.write(" Person's ID from servlet is: \n");
out.write(" ");
out.write(" \n");
out.write(" </body>\n");

From above code, we can understand that there is no existing object of Person available in the request scope, so container assigned a new object of Employee class. While printing properties, casting back to original object (Employee). I think container using introspection mechanism to identify the object type.

Alankar Yannam
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP's config parameters should be available from the implicit object "config" that is available in JSPs.

So you could call config.getInitParam(string) method to get to the initParam you are looking for.
Umesh Adtani
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just realized you may be looking to access these init parameters using EL.

Well, there is no implicit map available, so you should have to pass those in as attributes or paramters. Basically JSP would need to create a Map of init-param-values from config object and then call it a 'bean'. EL then can use configBean.paramName to get to initParam's value. It is tedious though. I wonder why there is no straightforward way from pageContext to get to initParams.
On top of spaghetti all covered in cheese, there was this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic