Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bean class code embended in JSP page wont work

Posted on 2004-03-29
7
Medium Priority
?
200 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
[X]
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
  • 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 120 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 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