By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,028 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,028 IT Pros & Developers. It's quick & easy.

Converting from java beans to c#

P: n/a
Hi,

I have an existing web application with java beans that I wanne migrate to
ASP.NET using C#.

The existing web application has some jsp files that use java beans as
follows:

....
<%@ page language="java" import="reportgen.*"%>
<%@ page import="java.lang.reflect.Array" %>
<jsp:useBean id="webAppConstants" scope="session"
class="reportgen.WebAppConstants">
</jsp:useBean>
<% webAppConstants.loadProperties(config); %>
<% session.setAttribute("WebAppConstants", webAppConstants);%>

<html>
<head>
<title></title>
....
....
<td bordercolor="#000000" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="340"
class="Text_Small">
<tr>
<td valign="top" height="72">
<%out.print(webAppConstants.WELCOME);%>
<br>
Now I'm looking for a possibility to use/make some C# objects that behave
nearly the same way that java beans do. That means I want to use them in the
html-code of an aspx-file.

In the above example webAppConstants is a selfdefined java class. But
because of "<jsp:useBean..." the class is instantiated to webAppConstants and
can be used in the following html-code.

I tried the following solution that should give me an object from a session:

<%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false"
Inherits="ReportGenerator.Login" %>
<%@ Import namespace="ReportGenerator" %>
<% ReportConstants reportConstants = new ReportConstants(); %>
<script Language="c#" runat="server">
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
<HTML>
....

But Session is unknown. So how do I get access to the session? Or is what
would be another solution.

Thanks in advance for any help.

Stephen
Nov 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
I believe the problem is that you need to put your code in the page_load
event. ASP.Net, unlike classic ASP, is event driven. That is, there's an
page_load event which fires when the page first loads.

Try:

<script Language="c#" runat="server">
void page_load(){
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];

}
</script>
not really sure what the goal of: > <% ReportConstants reportConstants = new
ReportConstants(); %> is, since you are later overwriting it with the
session variable...why create a new instance only to have it overwritten?
but if you do need, it too should likely be placed in page_load.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hi,

I have an existing web application with java beans that I wanne migrate to
ASP.NET using C#.

The existing web application has some jsp files that use java beans as
follows:

...
<%@ page language="java" import="reportgen.*"%>
<%@ page import="java.lang.reflect.Array" %>
<jsp:useBean id="webAppConstants" scope="session"
class="reportgen.WebAppConstants">
</jsp:useBean>
<% webAppConstants.loadProperties(config); %>
<% session.setAttribute("WebAppConstants", webAppConstants);%>

<html>
<head>
<title></title>
...
...
<td bordercolor="#000000" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
height="340"
class="Text_Small">
<tr>
<td valign="top" height="72">
<%out.print(webAppConstants.WELCOME);%>
<br>
Now I'm looking for a possibility to use/make some C# objects that behave
nearly the same way that java beans do. That means I want to use them in
the
html-code of an aspx-file.

In the above example webAppConstants is a selfdefined java class. But
because of "<jsp:useBean..." the class is instantiated to webAppConstants
and
can be used in the following html-code.

I tried the following solution that should give me an object from a
session:

<%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false"
Inherits="ReportGenerator.Login" %>
<%@ Import namespace="ReportGenerator" %>
<% ReportConstants reportConstants = new ReportConstants(); %>
<script Language="c#" runat="server">
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
<HTML>
...

But Session is unknown. So how do I get access to the session? Or is what
would be another solution.

Thanks in advance for any help.

Stephen

Nov 19 '05 #2

P: n/a
This is kind of hard to say, but you're putting the cart before the horse
here. What I mean is that, rather than trying to make ASP.Net behave like
Java Beans, or ASP, which is the closest thing in the Microsoft family to
Java Beans. You need to be thinking more about how to accomplish WHAT you
accomplish in Java Beans with ASP.net, not HOW. That is, any programming
technology exists for basically the same purpose: To satisfy requirements,
or to "make something happen." Session State, for example, exists for the
purpose of maintaining state acrosss a single user Session in a stateless
HTTP environment. And indeed, ASP.Net has Session State, and it serves the
same purpose. But you're talking about nailing nails with a hammer gun
instead of a hammer, and you want to know where to hit the nail with the
hammer gun. The end is the same; the means is entirely different. In other
words, you need to either bite the proverbial bullet, and learn how to work
with the ASP.Net object model, or stick with what you know. If you hit nails
with a hammer gun, eventually, the gun breaks. On the other hand, if you use
a hammer gun as it was designed, you can drive a lot more nails in a lot
less time.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hi,

I have an existing web application with java beans that I wanne migrate to
ASP.NET using C#.

The existing web application has some jsp files that use java beans as
follows:

...
<%@ page language="java" import="reportgen.*"%>
<%@ page import="java.lang.reflect.Array" %>
<jsp:useBean id="webAppConstants" scope="session"
class="reportgen.WebAppConstants">
</jsp:useBean>
<% webAppConstants.loadProperties(config); %>
<% session.setAttribute("WebAppConstants", webAppConstants);%>

<html>
<head>
<title></title>
...
...
<td bordercolor="#000000" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
height="340"
class="Text_Small">
<tr>
<td valign="top" height="72">
<%out.print(webAppConstants.WELCOME);%>
<br>
Now I'm looking for a possibility to use/make some C# objects that behave
nearly the same way that java beans do. That means I want to use them in
the
html-code of an aspx-file.

In the above example webAppConstants is a selfdefined java class. But
because of "<jsp:useBean..." the class is instantiated to webAppConstants
and
can be used in the following html-code.

I tried the following solution that should give me an object from a
session:

<%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false"
Inherits="ReportGenerator.Login" %>
<%@ Import namespace="ReportGenerator" %>
<% ReportConstants reportConstants = new ReportConstants(); %>
<script Language="c#" runat="server">
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
<HTML>
...

But Session is unknown. So how do I get access to the session? Or is what
would be another solution.

Thanks in advance for any help.

Stephen

Nov 19 '05 #3

P: n/a
Hi Karl,

I already tried this. The problem with this approach is that reportConstants
is only accessible in the scope of page_load. Even if I put the declaration
of reportConstants before the scope of page_load I get the runtime error
message "System.NullReferenceException: Object reference not set to an
instance of an object."

I figured out another solution for the static parts because now I know how
to access html tags from the codebehind file.

But there's still one remaining problem: How do I access parts in
JavaScript. The following line is an example how it worked with Java:
....
document.getElementById("database").value="<%
out.print(reportConstants.DBNAME); %>";
....

Bernd

"Karl Seguin" wrote:
I believe the problem is that you need to put your code in the page_load
event. ASP.Net, unlike classic ASP, is event driven. That is, there's an
page_load event which fires when the page first loads.

Try:

<script Language="c#" runat="server">
void page_load(){
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];

}
</script>
not really sure what the goal of: > <% ReportConstants reportConstants = new
ReportConstants(); %> is, since you are later overwriting it with the
session variable...why create a new instance only to have it overwritten?
but if you do need, it too should likely be placed in page_load.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hi,

I have an existing web application with java beans that I wanne migrate to
ASP.NET using C#.

The existing web application has some jsp files that use java beans as
follows:

...
<%@ page language="java" import="reportgen.*"%>
<%@ page import="java.lang.reflect.Array" %>
<jsp:useBean id="webAppConstants" scope="session"
class="reportgen.WebAppConstants">
</jsp:useBean>
<% webAppConstants.loadProperties(config); %>
<% session.setAttribute("WebAppConstants", webAppConstants);%>

<html>
<head>
<title></title>
...
...
<td bordercolor="#000000" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
height="340"
class="Text_Small">
<tr>
<td valign="top" height="72">
<%out.print(webAppConstants.WELCOME);%>
<br>
Now I'm looking for a possibility to use/make some C# objects that behave
nearly the same way that java beans do. That means I want to use them in
the
html-code of an aspx-file.

In the above example webAppConstants is a selfdefined java class. But
because of "<jsp:useBean..." the class is instantiated to webAppConstants
and
can be used in the following html-code.

I tried the following solution that should give me an object from a
session:

<%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false"
Inherits="ReportGenerator.Login" %>
<%@ Import namespace="ReportGenerator" %>
<% ReportConstants reportConstants = new ReportConstants(); %>
<script Language="c#" runat="server">
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
<HTML>
...

But Session is unknown. So how do I get access to the session? Or is what
would be another solution.

Thanks in advance for any help.

Stephen


Nov 19 '05 #4

P: n/a
Hi Kevin,

yes I have to learn more about ASP.Net. But metaphoric answers from people
who seem to come straight out of a DIY store are not really helpfull for
anybody.

Bernd
"Kevin Spencer" wrote:
This is kind of hard to say, but you're putting the cart before the horse
here. What I mean is that, rather than trying to make ASP.Net behave like
Java Beans, or ASP, which is the closest thing in the Microsoft family to
Java Beans. You need to be thinking more about how to accomplish WHAT you
accomplish in Java Beans with ASP.net, not HOW. That is, any programming
technology exists for basically the same purpose: To satisfy requirements,
or to "make something happen." Session State, for example, exists for the
purpose of maintaining state acrosss a single user Session in a stateless
HTTP environment. And indeed, ASP.Net has Session State, and it serves the
same purpose. But you're talking about nailing nails with a hammer gun
instead of a hammer, and you want to know where to hit the nail with the
hammer gun. The end is the same; the means is entirely different. In other
words, you need to either bite the proverbial bullet, and learn how to work
with the ASP.Net object model, or stick with what you know. If you hit nails
with a hammer gun, eventually, the gun breaks. On the other hand, if you use
a hammer gun as it was designed, you can drive a lot more nails in a lot
less time.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hi,

I have an existing web application with java beans that I wanne migrate to
ASP.NET using C#.

The existing web application has some jsp files that use java beans as
follows:

...
<%@ page language="java" import="reportgen.*"%>
<%@ page import="java.lang.reflect.Array" %>
<jsp:useBean id="webAppConstants" scope="session"
class="reportgen.WebAppConstants">
</jsp:useBean>
<% webAppConstants.loadProperties(config); %>
<% session.setAttribute("WebAppConstants", webAppConstants);%>

<html>
<head>
<title></title>
...
...
<td bordercolor="#000000" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
height="340"
class="Text_Small">
<tr>
<td valign="top" height="72">
<%out.print(webAppConstants.WELCOME);%>
<br>
Now I'm looking for a possibility to use/make some C# objects that behave
nearly the same way that java beans do. That means I want to use them in
the
html-code of an aspx-file.

In the above example webAppConstants is a selfdefined java class. But
because of "<jsp:useBean..." the class is instantiated to webAppConstants
and
can be used in the following html-code.

I tried the following solution that should give me an object from a
session:

<%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false"
Inherits="ReportGenerator.Login" %>
<%@ Import namespace="ReportGenerator" %>
<% ReportConstants reportConstants = new ReportConstants(); %>
<script Language="c#" runat="server">
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
<HTML>
...

But Session is unknown. So how do I get access to the session? Or is what
would be another solution.

Thanks in advance for any help.

Stephen


Nov 19 '05 #5

P: n/a
As is often the case, I have to agree with what Kevin also posted.

one question is why does this need to be done in javascript?

what is "database" ? a textbox? then you should do it like:

<asp:textbox id="database" runat="server" />

and in your codebehind use:

database.Text = reportContants.DBNAME;
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
Hi Karl,

I already tried this. The problem with this approach is that
reportConstants
is only accessible in the scope of page_load. Even if I put the
declaration
of reportConstants before the scope of page_load I get the runtime error
message "System.NullReferenceException: Object reference not set to an
instance of an object."

I figured out another solution for the static parts because now I know how
to access html tags from the codebehind file.

But there's still one remaining problem: How do I access parts in
JavaScript. The following line is an example how it worked with Java:
...
document.getElementById("database").value="<%
out.print(reportConstants.DBNAME); %>";
...

Bernd

"Karl Seguin" wrote:
I believe the problem is that you need to put your code in the page_load
event. ASP.Net, unlike classic ASP, is event driven. That is, there's
an
page_load event which fires when the page first loads.

Try:

<script Language="c#" runat="server">
void page_load(){
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];

}
</script>
not really sure what the goal of: > <% ReportConstants reportConstants =
new
ReportConstants(); %> is, since you are later overwriting it with the
session variable...why create a new instance only to have it overwritten?
but if you do need, it too should likely be placed in page_load.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
> Hi,
>
> I have an existing web application with java beans that I wanne migrate
> to
> ASP.NET using C#.
>
> The existing web application has some jsp files that use java beans as
> follows:
>
> ...
> <%@ page language="java" import="reportgen.*"%>
> <%@ page import="java.lang.reflect.Array" %>
> <jsp:useBean id="webAppConstants" scope="session"
> class="reportgen.WebAppConstants">
> </jsp:useBean>
> <% webAppConstants.loadProperties(config); %>
> <% session.setAttribute("WebAppConstants", webAppConstants);%>
>
> <html>
> <head>
> <title></title>
> ...
> ...
> <td bordercolor="#000000" valign="top">
> <table width="100%" border="0" cellspacing="0" cellpadding="0"
> height="340"
> class="Text_Small">
> <tr>
> <td valign="top" height="72">
> <%out.print(webAppConstants.WELCOME);%>
> <br>
>
>
> Now I'm looking for a possibility to use/make some C# objects that
> behave
> nearly the same way that java beans do. That means I want to use them
> in
> the
> html-code of an aspx-file.
>
> In the above example webAppConstants is a selfdefined java class. But
> because of "<jsp:useBean..." the class is instantiated to
> webAppConstants
> and
> can be used in the following html-code.
>
> I tried the following solution that should give me an object from a
> session:
>
> <%@ Page CodeBehind="Login.aspx.cs" Language="c#"
> AutoEventWireup="false"
> Inherits="ReportGenerator.Login" %>
> <%@ Import namespace="ReportGenerator" %>
> <% ReportConstants reportConstants = new ReportConstants(); %>
> <script Language="c#" runat="server">
> ReportConstants reportConstants =
> (ReportConstants)Session["ReportConstants"];
> </script>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
> <HTML>
> ...
>
> But Session is unknown. So how do I get access to the session? Or is
> what
> would be another solution.
>
> Thanks in advance for any help.
>
> Stephen


Nov 19 '05 #6

P: n/a
I really like this analogy.. can I quote you on it?
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u2****************@TK2MSFTNGP12.phx.gbl...
This is kind of hard to say, but you're putting the cart before the horse
here. What I mean is that, rather than trying to make ASP.Net behave like
Java Beans, or ASP, which is the closest thing in the Microsoft family to
Java Beans. You need to be thinking more about how to accomplish WHAT you
accomplish in Java Beans with ASP.net, not HOW. That is, any programming
technology exists for basically the same purpose: To satisfy requirements,
or to "make something happen." Session State, for example, exists for the
purpose of maintaining state acrosss a single user Session in a stateless
HTTP environment. And indeed, ASP.Net has Session State, and it serves the
same purpose. But you're talking about nailing nails with a hammer gun
instead of a hammer, and you want to know where to hit the nail with the
hammer gun. The end is the same; the means is entirely different. In other
words, you need to either bite the proverbial bullet, and learn how to work with the ASP.Net object model, or stick with what you know. If you hit nails with a hammer gun, eventually, the gun breaks. On the other hand, if you use a hammer gun as it was designed, you can drive a lot more nails in a lot
less time.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hi,

I have an existing web application with java beans that I wanne migrate to ASP.NET using C#.

The existing web application has some jsp files that use java beans as
follows:

...
<%@ page language="java" import="reportgen.*"%>
<%@ page import="java.lang.reflect.Array" %>
<jsp:useBean id="webAppConstants" scope="session"
class="reportgen.WebAppConstants">
</jsp:useBean>
<% webAppConstants.loadProperties(config); %>
<% session.setAttribute("WebAppConstants", webAppConstants);%>

<html>
<head>
<title></title>
...
...
<td bordercolor="#000000" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0"
height="340"
class="Text_Small">
<tr>
<td valign="top" height="72">
<%out.print(webAppConstants.WELCOME);%>
<br>
Now I'm looking for a possibility to use/make some C# objects that behave nearly the same way that java beans do. That means I want to use them in
the
html-code of an aspx-file.

In the above example webAppConstants is a selfdefined java class. But
because of "<jsp:useBean..." the class is instantiated to webAppConstants and
can be used in the following html-code.

I tried the following solution that should give me an object from a
session:

<%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="ReportGenerator.Login" %>
<%@ Import namespace="ReportGenerator" %>
<% ReportConstants reportConstants = new ReportConstants(); %>
<script Language="c#" runat="server">
ReportConstants reportConstants =
(ReportConstants)Session["ReportConstants"];
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
<HTML>
...

But Session is unknown. So how do I get access to the session? Or is what would be another solution.

Thanks in advance for any help.

Stephen


Nov 19 '05 #7

P: n/a
Why thank you Sean. All of my ramblings are copyright-free!

--
:-D,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Sean M" <ta******@hotmail.com> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
I really like this analogy.. can I quote you on it?
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u2****************@TK2MSFTNGP12.phx.gbl...
This is kind of hard to say, but you're putting the cart before the horse
here. What I mean is that, rather than trying to make ASP.Net behave like
Java Beans, or ASP, which is the closest thing in the Microsoft family to
Java Beans. You need to be thinking more about how to accomplish WHAT you
accomplish in Java Beans with ASP.net, not HOW. That is, any programming
technology exists for basically the same purpose: To satisfy
requirements,
or to "make something happen." Session State, for example, exists for the
purpose of maintaining state acrosss a single user Session in a stateless
HTTP environment. And indeed, ASP.Net has Session State, and it serves
the
same purpose. But you're talking about nailing nails with a hammer gun
instead of a hammer, and you want to know where to hit the nail with the
hammer gun. The end is the same; the means is entirely different. In
other
words, you need to either bite the proverbial bullet, and learn how to

work
with the ASP.Net object model, or stick with what you know. If you hit

nails
with a hammer gun, eventually, the gun breaks. On the other hand, if you

use
a hammer gun as it was designed, you can drive a lot more nails in a lot
less time.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
> Hi,
>
> I have an existing web application with java beans that I wanne migrate to > ASP.NET using C#.
>
> The existing web application has some jsp files that use java beans as
> follows:
>
> ...
> <%@ page language="java" import="reportgen.*"%>
> <%@ page import="java.lang.reflect.Array" %>
> <jsp:useBean id="webAppConstants" scope="session"
> class="reportgen.WebAppConstants">
> </jsp:useBean>
> <% webAppConstants.loadProperties(config); %>
> <% session.setAttribute("WebAppConstants", webAppConstants);%>
>
> <html>
> <head>
> <title></title>
> ...
> ...
> <td bordercolor="#000000" valign="top">
> <table width="100%" border="0" cellspacing="0" cellpadding="0"
> height="340"
> class="Text_Small">
> <tr>
> <td valign="top" height="72">
> <%out.print(webAppConstants.WELCOME);%>
> <br>
>
>
> Now I'm looking for a possibility to use/make some C# objects that behave > nearly the same way that java beans do. That means I want to use them
> in
> the
> html-code of an aspx-file.
>
> In the above example webAppConstants is a selfdefined java class. But
> because of "<jsp:useBean..." the class is instantiated to webAppConstants > and
> can be used in the following html-code.
>
> I tried the following solution that should give me an object from a
> session:
>
> <%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" > Inherits="ReportGenerator.Login" %>
> <%@ Import namespace="ReportGenerator" %>
> <% ReportConstants reportConstants = new ReportConstants(); %>
> <script Language="c#" runat="server">
> ReportConstants reportConstants =
> (ReportConstants)Session["ReportConstants"];
> </script>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
> <HTML>
> ...
>
> But Session is unknown. So how do I get access to the session? Or is what > would be another solution.
>
> Thanks in advance for any help.
>
> Stephen



Nov 19 '05 #8

P: n/a
Well, Stephen,

I wouldn't be here if I was a pure DIY guy! I'd be off somewhere ignoring
the rest of the world.

Notice that I did mention that you have the option of sticking with what you
know. Otherwise, you're goint o have to put on your thinking cap for a very
long time, along with the rest of use exploring this incredibly vast world
of .Net technology.

But, so you don't feel that I've completely abandoned you to your own
devices, I can provide you with a small piece of information regarding the
code you posted:
> <% ReportConstants reportConstants = new ReportConstants(); %>
> <script Language="c#" runat="server">
> ReportConstants reportConstants =
> (ReportConstants)Session["ReportConstants"];
> </script>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
> <HTML>
> ...
>
> But Session is unknown. So how do I get access to the session? Or is
> what
> would be another solution.

I would guess that it isn't Session that is "unknown." It looks like
Session["ReportConstants"] is null. I don't see where you've initialized it
prior to attempting to cast it as a ReportConstants class.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com... Hi Kevin,

yes I have to learn more about ASP.Net. But metaphoric answers from people
who seem to come straight out of a DIY store are not really helpfull for
anybody.

Bernd
"Kevin Spencer" wrote:
This is kind of hard to say, but you're putting the cart before the horse
here. What I mean is that, rather than trying to make ASP.Net behave like
Java Beans, or ASP, which is the closest thing in the Microsoft family to
Java Beans. You need to be thinking more about how to accomplish WHAT you
accomplish in Java Beans with ASP.net, not HOW. That is, any programming
technology exists for basically the same purpose: To satisfy
requirements,
or to "make something happen." Session State, for example, exists for the
purpose of maintaining state acrosss a single user Session in a stateless
HTTP environment. And indeed, ASP.Net has Session State, and it serves
the
same purpose. But you're talking about nailing nails with a hammer gun
instead of a hammer, and you want to know where to hit the nail with the
hammer gun. The end is the same; the means is entirely different. In
other
words, you need to either bite the proverbial bullet, and learn how to
work
with the ASP.Net object model, or stick with what you know. If you hit
nails
with a hammer gun, eventually, the gun breaks. On the other hand, if you
use
a hammer gun as it was designed, you can drive a lot more nails in a lot
less time.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Stephen H." <St******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
> Hi,
>
> I have an existing web application with java beans that I wanne migrate
> to
> ASP.NET using C#.
>
> The existing web application has some jsp files that use java beans as
> follows:
>
> ...
> <%@ page language="java" import="reportgen.*"%>
> <%@ page import="java.lang.reflect.Array" %>
> <jsp:useBean id="webAppConstants" scope="session"
> class="reportgen.WebAppConstants">
> </jsp:useBean>
> <% webAppConstants.loadProperties(config); %>
> <% session.setAttribute("WebAppConstants", webAppConstants);%>
>
> <html>
> <head>
> <title></title>
> ...
> ...
> <td bordercolor="#000000" valign="top">
> <table width="100%" border="0" cellspacing="0" cellpadding="0"
> height="340"
> class="Text_Small">
> <tr>
> <td valign="top" height="72">
> <%out.print(webAppConstants.WELCOME);%>
> <br>
>
>
> Now I'm looking for a possibility to use/make some C# objects that
> behave
> nearly the same way that java beans do. That means I want to use them
> in
> the
> html-code of an aspx-file.
>
> In the above example webAppConstants is a selfdefined java class. But
> because of "<jsp:useBean..." the class is instantiated to
> webAppConstants
> and
> can be used in the following html-code.
>
> I tried the following solution that should give me an object from a
> session:
>
> <%@ Page CodeBehind="Login.aspx.cs" Language="c#"
> AutoEventWireup="false"
> Inherits="ReportGenerator.Login" %>
> <%@ Import namespace="ReportGenerator" %>
> <% ReportConstants reportConstants = new ReportConstants(); %>
> <script Language="c#" runat="server">
> ReportConstants reportConstants =
> (ReportConstants)Session["ReportConstants"];
> </script>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" >
> <HTML>
> ...
>
> But Session is unknown. So how do I get access to the session? Or is
> what
> would be another solution.
>
> Thanks in advance for any help.
>
> Stephen


Nov 19 '05 #9

P: n/a
Kevin Spencer shared this with us in
microsoft.public.dotnet.framework.aspnet:
Why thank you Sean. All of my ramblings are copyright-free!


# rambling starts here

Do you mean Public Domain, Open License, Shared License, Creative
Common License, Open Publication license, or some other licensing
scam^Wscheme?
;-)

--
Amedee Van Gasse
Nov 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.