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
Solved

bean class code embended in JSP page wont work

Posted on 2004-03-29
7
197 Views
Last Modified: 2010-04-01
i am using Sun Java System Application Server.

i found that my bean class code that embended in JSP page wont work,
--------------------------------------------------------------------------
<HTML>
<jsp:declaration>
// this is a local "helper" bean for processing the HTML form
static public class localBean
{
private String value;
public String getValue() { return value;}
public void setValue(String s) { value = s; }
}
</jsp:declaration>
<jsp:useBean id="localBean" scope="application" class="localBean" >
<%-- Every time we create the bean, initialize the string --%>
<jsp:setProperty name="localBean" property="value" value="World" />
</jsp:useBean>
<%-- Whatever HTTP parameters we have,
try to set an analogous bean property --%>
<jsp:setProperty name="localBean" property="*" />
<HEAD><TITLE>HelloWorld w/ JavaBean</TITLE></HEAD>
<BODY>
<CENTER>
<P><H1>Hello
<jsp:getProperty name='localBean' property='value'/></H1></P>
<FORM method=post>
Enter a name to be greeted:
      <INPUT TYPE="text" SIZE="32" NAME="value"
VALUE="<jsp:getProperty name='localBean' property='value'/>">
<BR>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</CENTER>
</BODY>
</HTML>
--------------------------------------------------------------------------
i need to explicitly create a C:\Learning\JSP\WEB-INF\classes folder, extract out the embended bean code from JSP page, compile it to class file and put it in the previous folder that created explicitly. then only it will work.

may i know how can i keep continue to make the bean class code embended in JSP page work without explicitly create a class file?

thank you.

regards
yan cheng
0
Comment
Question by:yccheok
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:searlas
ID: 10705281
So, you're saying if you extract out the localbean declaration and compile to localbean.class it works?
The problem is that your class="localbean" attribute assumes your localbean is not defined in a package.  However, when your JSP gets compiled it is put into a package as thought it had "package jsp_servlet.subdir.subdir.subdir;" - depending on the path to your JSP.

0
 

Author Comment

by:yccheok
ID: 10705909
ya, that's it. then, how do i make my JSP noe the code is embended into the JSP file?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10710757
no, you cannot!
0
 
LVL 7

Accepted Solution

by:
searlas earned 30 total points
ID: 10712204
I'd say, you should not - and I've never seen anyone sick enough to try.  But it is possible.

I do have a proof of concept; but it suffers from the problem that if you edit the jsp (and cause it to recompile) the instance of the inner class stored in the session no longer casts to the correct class, and so the <jsp:useBean....> throws an Exception.  Addtionally, I suspect the implementation is app-server depenedent.

Basically, yccheok, don't do this.  If you want advice on how to better structure your JSP's and bean class there's plenty of experts around here who can do that.  To continue down this track for anything other than an experiment is madness.

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10716181
you are right searlas.
>> I suspect the implementation is app-server depenedent
I affirm it. I should have been more clearly but that's why I said no.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project in eclipse 11 60
immutable object concept 5 127
memory representation of int[][][] a=new int[2][][]; 10 60
excpetion with multiple catch 11 121
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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