Solved

bean class code embended in JSP page wont work

Posted on 2004-03-29
7
192 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now