JSP questions  
Author Message
Fangyu.Guan





PostPosted: 2004-11-11 6:05:00 Top

java-programmer, JSP questions have some questions about JavaServer Pages to ask

1. I made several input fields for user to input the height, width and
other stuff to create a table. how can I make the font in color red in
first row and first column automaticly and font in other rows and
columns remain the same color?

2. I want to add a title inside the table that need to colspan the
rest of the table. Becasue I don't know what # the user will input for
columns, so I can't set it before user input. so plz help me on this.

3. Randomly place an input field in one of the cells ?a different
cell on each refresh. If the user enters the correct product there and
changes the focus (by clicking outside the field), a Javascript
provided by the jsp page checks the answer and makes appropriate alert

My jsp file looks like this:

<HTML>
<head></head>
<BODY>

<%
String s2 = request.getParameter("Bsize") ;
s2 = s2.trim();
out.print("<table bgcolor=silver border= ");
out.print(s2);
out.print(" ");
String s3 = request.getParameter("Bcolor") ;
s3 = s3.trim();
out.print("bordercolor= ");
out.print(s3);
out.print(">");

String m1 = request.getParameter("mName") ;
m1 = m1.trim();
int M = Integer.parseInt(m1);

String n1 = request.getParameter("nName") ;
n1 = n1.trim();
int N = Integer.parseInt(n1);

String s = request.getParameter("FullName") ;
s = s.trim();
out.println("<font color=red size=6>");
out.println(s);
out.println("'s table is: </font>");

out.println("<tr colspan= ");

out.print(m1);

out.println(">");
out.print("<th> Numbers </th> </tr>");


for (int i =1; i<= M; i++ )
{
out.println("<tr width= 10 >");

for (int j =1; j<= N; j++ )
{
out.println("<th >");
out.println(j * i);
out.println("</th>");
}

out.println("</tr>");

}
%>

</table>
 
Hal Rosser





PostPosted: 2004-11-11 6:48:00 Top

java-programmer >> JSP questions You can use CSS (Cascading style sheets) to do that.

"redpanda" <email***@***.com> wrote in message
news:email***@***.com...
> have some questions about JavaServer Pages to ask
>
> 1. I made several input fields for user to input the height, width and
> other stuff to create a table. how can I make the font in color red in
> first row and first column automaticly and font in other rows and
> columns remain the same color?
>
> 2. I want to add a title inside the table that need to colspan the
> rest of the table. Becasue I don't know what # the user will input for
> columns, so I can't set it before user input. so plz help me on this.
>
> 3. Randomly place an input field in one of the cells - a different
> cell on each refresh. If the user enters the correct product there and
> changes the focus (by clicking outside the field), a Javascript
> provided by the jsp page checks the answer and makes appropriate alert
>
> My jsp file looks like this:
>
> <HTML>
> <head></head>
> <BODY>
>
> <%
> String s2 = request.getParameter("Bsize") ;
> s2 = s2.trim();
> out.print("<table bgcolor=silver border= ");
> out.print(s2);
> out.print(" ");
> String s3 = request.getParameter("Bcolor") ;
> s3 = s3.trim();
> out.print("bordercolor= ");
> out.print(s3);
> out.print(">");
>
> String m1 = request.getParameter("mName") ;
> m1 = m1.trim();
> int M = Integer.parseInt(m1);
>
> String n1 = request.getParameter("nName") ;
> n1 = n1.trim();
> int N = Integer.parseInt(n1);
>
> String s = request.getParameter("FullName") ;
> s = s.trim();
> out.println("<font color=red size=6>");
> out.println(s);
> out.println("'s table is: </font>");
>
> out.println("<tr colspan= ");
>
> out.print(m1);
>
> out.println(">");
> out.print("<th> Numbers </th> </tr>");
>
>
> for (int i =1; i<= M; i++ )
> {
> out.println("<tr width= 10 >");
>
> for (int j =1; j<= N; j++ )
> {
> out.println("<th >");
> out.println(j * i);
> out.println("</th>");
> }
>
> out.println("</tr>");
>
> }
> %>
>
> </table>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004


 
Fangyu.Guan





PostPosted: 2004-11-12 3:54:00 Top

java-programmer >> JSP questions I don't get it what you are saying, can you show me an example?


"Hal Rosser" <email***@***.com> wrote in message news:<ATwkd.3232$email***@***.com>...
> You can use CSS (Cascading style sheets) to do that.
>
> "redpanda" <email***@***.com> wrote in message
> news:email***@***.com...
> > have some questions about JavaServer Pages to ask
> >
> > 1. I made several input fields for user to input the height, width and
> > other stuff to create a table. how can I make the font in color red in
> > first row and first column automaticly and font in other rows and
> > columns remain the same color?
> >
> > 2. I want to add a title inside the table that need to colspan the
> > rest of the table. Becasue I don't know what # the user will input for
> > columns, so I can't set it before user input. so plz help me on this.
> >
> > 3. Randomly place an input field in one of the cells - a different
> > cell on each refresh. If the user enters the correct product there and
> > changes the focus (by clicking outside the field), a Javascript
> > provided by the jsp page checks the answer and makes appropriate alert
> >
> > My jsp file looks like this:
> >
> > <HTML>
> > <head></head>
> > <BODY>
> >
> > <%
> > String s2 = request.getParameter("Bsize") ;
> > s2 = s2.trim();
> > out.print("<table bgcolor=silver border= ");
> > out.print(s2);
> > out.print(" ");
> > String s3 = request.getParameter("Bcolor") ;
> > s3 = s3.trim();
> > out.print("bordercolor= ");
> > out.print(s3);
> > out.print(">");
> >
> > String m1 = request.getParameter("mName") ;
> > m1 = m1.trim();
> > int M = Integer.parseInt(m1);
> >
> > String n1 = request.getParameter("nName") ;
> > n1 = n1.trim();
> > int N = Integer.parseInt(n1);
> >
> > String s = request.getParameter("FullName") ;
> > s = s.trim();
> > out.println("<font color=red size=6>");
> > out.println(s);
> > out.println("'s table is: </font>");
> >
> > out.println("<tr colspan= ");
> >
> > out.print(m1);
> >
> > out.println(">");
> > out.print("<th> Numbers </th> </tr>");
> >
> >
> > for (int i =1; i<= M; i++ )
> > {
> > out.println("<tr width= 10 >");
> >
> > for (int j =1; j<= N; j++ )
> > {
> > out.println("<th >");
> > out.println(j * i);
> > out.println("</th>");
> > }
> >
> > out.println("</tr>");
> >
> > }
> > %>
> >
> > </table>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004
 
 
John C. Bollinger





PostPosted: 2004-11-12 5:04:00 Top

java-programmer >> JSP questions redpanda wrote:
> have some questions about JavaServer Pages to ask
>
> 1. I made several input fields for user to input the height, width and
> other stuff to create a table. how can I make the font in color red in
> first row and first column automaticly and font in other rows and
> columns remain the same color?

With JSP, always focus on the output. Most JSPs, including yours,
output HTML code. Determine how to code the visual effects you want in
HTML, then make your JSP produce that output. The HTML details are
off-topic for this newsgroup, but your main options are to use Cascading
Style Sheets (preferred) or to insert appropriate styling markup (e.g.
<font> elements, which you seem to already be doing).

> 2. I want to add a title inside the table that need to colspan the
> rest of the table. Becasue I don't know what # the user will input for
> columns, so I can't set it before user input. so plz help me on this.

I don't see how you expect it to work at all, then. When the JSP is
processing a request it has only the information available from the
request, session, and application. The JSP cannot presciently determine
how the client might react to the response, and it cannot do anything to
change the response once it is sent.

However, if you can create a table with the correct number of columns in
the first place then you necessarily know some number of columns that
the client *already* requested. Either you're missing something here or
I am.

> 3. Randomly place an input field in one of the cells ?a different
> cell on each refresh. If the user enters the correct product there and
> changes the focus (by clicking outside the field), a Javascript
> provided by the jsp page checks the answer and makes appropriate alert

So what's the problem?

If you need help with the Javascript then this is the wrong group.
Javascript is a completely separate language from Java, with only
superficial similarities.

If you need help generating a random number, then look into
java.util.Random and / or Math.random().

If you need help creating an input field then see my above comments
about HTML.

> My jsp file looks like this:
>
> <HTML>
> <head></head>
> <BODY>
>
> <%
> String s2 = request.getParameter("Bsize") ;
> s2 = s2.trim();
> out.print("<table bgcolor=silver border= ");
> out.print(s2);
> out.print(" ");
> String s3 = request.getParameter("Bcolor") ;
> s3 = s3.trim();
> out.print("bordercolor= ");
> out.print(s3);
> out.print(">");
>
> String m1 = request.getParameter("mName") ;
> m1 = m1.trim();
> int M = Integer.parseInt(m1);
>
> String n1 = request.getParameter("nName") ;
> n1 = n1.trim();
> int N = Integer.parseInt(n1);
>
> String s = request.getParameter("FullName") ;
> s = s.trim();
> out.println("<font color=red size=6>");
> out.println(s);
> out.println("'s table is: </font>");
>
> out.println("<tr colspan= ");
>
> out.print(m1);
>
> out.println(">");
> out.print("<th> Numbers </th> </tr>");
>
>
> for (int i =1; i<= M; i++ )
> {
> out.println("<tr width= 10 >");
>
> for (int j =1; j<= N; j++ )
> {
> out.println("<th >");
> out.println(j * i);
> out.println("</th>");
> }
>
> out.println("</tr>");
>
> }
> %>
>
> </table>

That is truly abominable JSP code. Sorry, but it is. See all those
out.print() and out.println() invocations? One of the original goals of
JSP was to not have to write servlet code that looks like that. Why are
you even bothering with JSP (instead of a pure servlet) if you're going
to write it like that? Also, most interested people agree that JSP
authors ought to focus on minimizing the use of scriptlets in their JSPs
[some even argue that scriptlets should be avoided altogether], but your
JSP is almost all one big scriptlet. Furthermore, unless you've
truncated it, your JSP doesn't even produce a valid HTML document. And
that's before we even get to not putting your HTML attribute values in
quotes, not using consistent coding conventions in your scriptlet code,
yada yada yada.


John Bollinger
email***@***.com
 
 
Sudsy





PostPosted: 2004-11-12 5:53:00 Top

java-programmer >> JSP questions John C. Bollinger wrote:
<snip>
> That is truly abominable JSP code. Sorry, but it is. See all those
> out.print() and out.println() invocations? One of the original goals of
> JSP was to not have to write servlet code that looks like that. Why are
> you even bothering with JSP (instead of a pure servlet) if you're going
> to write it like that? Also, most interested people agree that JSP
> authors ought to focus on minimizing the use of scriptlets in their JSPs
> [some even argue that scriptlets should be avoided altogether], but your
> JSP is almost all one big scriptlet. Furthermore, unless you've
> truncated it, your JSP doesn't even produce a valid HTML document. And
> that's before we even get to not putting your HTML attribute values in
> quotes, not using consistent coding conventions in your scriptlet code,
> yada yada yada.

Count me among those who eschew scriptlets. Either use existing tag
libraries or roll your own. It's not that difficult and makes the JSP
so much easier to read. It's also easier on your graphic artists when
you explain that they just need to use a particular tag to obtain
desired functionality. This will be familiar since HTML is merely tag
markup. Embedded Java code just makes their heads spin... ;-)

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

 
 
Hal Rosser





PostPosted: 2004-11-12 11:49:00 Top

java-programmer >> JSP questions <html>
<head>
<style>
.makeRed {color:red;}
</style>
</head>
<Body>
.....in the body use if statement in the code
if the condition warrants red text then have the code make the <td> tag like
this
<td class='makeRed>
... there's a free css tutorial on www.w3schools.com



"redpanda" <email***@***.com> wrote in message
news:email***@***.com...
> I don't get it what you are saying, can you show me an example?
>
>
> "Hal Rosser" <email***@***.com> wrote in message
news:<ATwkd.3232$email***@***.com>...
> > You can use CSS (Cascading style sheets) to do that.
> >



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004


 
 
jwren





PostPosted: 2007-10-23 5:32:00 Top

java-programmer >> JSP questions Hey guys,

I am working on a JSP website on JRE1.4. I am trying to find some
good packages to use to speed up development because the project
currently uses no framework whatsoever. Would anyone mind
recommending some good packages? So far Struts looks worthwhile.

Since I am from a C# background:

JRE1.4 can't support Nullable<T>, so what is the best practice for
representing null value types?

Does JRE1.4 have an alternative to C#'s using statement?

Thanks in advance,
James

 
 
Arne Vajh鴍





PostPosted: 2007-10-23 6:56:00 Top

java-programmer >> JSP questions jwren wrote:
> I am working on a JSP website on JRE1.4. I am trying to find some
> good packages to use to speed up development because the project
> currently uses no framework whatsoever. Would anyone mind
> recommending some good packages? So far Struts looks worthwhile.

JSF will probably look more ASP.NET like to you.

> Since I am from a C# background:
>
> JRE1.4 can't support Nullable<T>, so what is the best practice for
> representing null value types?

Use the wrapper classes Integer, Double etc..

> Does JRE1.4 have an alternative to C#'s using statement?

No.

You will need to use try finally.

Arne
 
 
Lew





PostPosted: 2007-10-23 8:52:00 Top

java-programmer >> JSP questions jwren wrote:
>> I am working on a JSP website on JRE1.4. I am trying to find some
>> good packages to use to speed up development because the project
>> currently uses no framework whatsoever. Would anyone mind
>> recommending some good packages? So far Struts looks worthwhile.

Arne Vajh酶j wrote:
> JSF will probably look more ASP.NET like to you.

And is much more powerful and flexible.

jwren wrote:
>> Since I am from a C# background:
>>
>> JRE1.4 can't support Nullable<T>, so what is the best practice for
>> representing null value types?

Arne Vajh酶j wrote:
> Use the wrapper classes Integer, Double etc..

There is no direct Java equivalent to C#'s Nullable<T>.

What are you trying to do with it in Java?

jwren wrote:
>> Does JRE1.4 have an alternative to C#'s using statement?

Arne Vajh酶j wrote:
> No.
>
> You will need to use try finally.

And should use Java 6, the current version. Java 1.4 is in End-of-Life, it
lacks generics and other useful features, and it is slower than later
versions. Particularly coming from C#, you should find Java 5 or 6 much more
comfortable than the obsolescent version.

P.S., Arne is known to be very knowledgeable about both C# and Java.

--
Lew
 
 
jwren





PostPosted: 2007-10-23 9:15:00 Top

java-programmer >> JSP questions Hi Lew,

Is 1.6 backward compatible with 1.4?

> >> JRE1.4 can't support Nullable<T>, so what is the best practice for
> >> representing null value types?
> Arne Vajh鴍 wrote:
> > Use the wrapper classes Integer, Double etc..
>
> There is no direct Java equivalent to C#'s Nullable<T>.
>
> What are you trying to do with it in Java?
>

I need it for database access. Using the wrappers as Arne suggested
sounds like a good enough solution.

Thanks,
James



 
 
Arne Vajh鴍





PostPosted: 2007-10-23 9:18:00 Top

java-programmer >> JSP questions jwren wrote:
> Is 1.6 backward compatible with 1.4?

For most practical purposes yes.

Arne
 
 
Lew





PostPosted: 2007-10-23 11:55:00 Top

java-programmer >> JSP questions jwren wrote:
> Hi Lew,
>
> Is 1.6 backward compatible with 1.4?
>
>>>> JRE1.4 can't support Nullable<T>, so what is the best practice for
>>>> representing null value types?
>> Arne Vajh酶j wrote:
>>> Use the wrapper classes Integer, Double etc..
>> There is no direct Java equivalent to C#'s Nullable<T>.
>>
>> What are you trying to do with it in Java?
>>
>
> I need it for database access. Using the wrappers as Arne suggested
> sounds like a good enough solution.

FYI, for DATETIME in JDBC there is the java.sql.Date type.

The java.sql package has classes and interfaces to support DB access, and they
impose certain idioms on things like setting PreparedStatement
<http://java.sun.com/javase/6/docs/api/java/sql/PreparedStatement.html>
positional paramaters or retrieving columns from a ResultSet
<http://java.sun.com/javase/6/docs/api/java/sql/ResultSet.html>
or its RowSet subtype
<http://java.sun.com/javase/6/docs/api/javax/sql/RowSet.html>
. They indicate what Java types canonically map to which SQL types. The Java
Persistence API (JPA) also resolves certain fundamental matters of
object-relational mapping.

--
Lew
 
 
David Segall





PostPosted: 2007-10-23 14:50:00 Top

java-programmer >> JSP questions Arne Vajh鴍 <email***@***.com> wrote:

>jwren wrote:
>> I am working on a JSP website on JRE1.4. I am trying to find some
>> good packages to use to speed up development because the project
>> currently uses no framework whatsoever. Would anyone mind
>> recommending some good packages? So far Struts looks worthwhile.
>
>JSF will probably look more ASP.NET like to you.
And there's a drag and drop GUI development tool with remote debugging
for JSF. <http://www.netbeans.org/products/visualweb/>
 
 
QXJuZSBWYWpow7hq





PostPosted: 2007-10-28 1:19:00 Top

java-programmer >> JSP questions Lew wrote:
> FYI, for DATETIME in JDBC there is the java.sql.Date type.

Or java.sql.Timestamp if the tim eportion is needed.

> The java.sql package has classes and interfaces to support DB access,
> and they impose certain idioms on things like setting PreparedStatement
> <http://java.sun.com/javase/6/docs/api/java/sql/PreparedStatement.html>
> positional paramaters or retrieving columns from a ResultSet

It is very similar to .NET Parameters. The biggest difference is
that JDBC PreparedStatement is always positional, while in .NET it
uses names for some provides and positions for other provides
(a bit tricky, because it always allows names, but it really uses
positions for the last category).

> <http://java.sun.com/javase/6/docs/api/java/sql/ResultSet.html>

Similar to .NET DataReader.

> <http://java.sun.com/javase/6/docs/api/javax/sql/RowSet.html>

Somewhat similar to .NET DataSet.

Arne