473,830 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JSP Getting Started

539 Contributor
I have a subject that covers JSP(new to me), accessing database through JSP(new to me), applets, UML(also new to me)

So, as im learning java, all i did to learn faster is i've created some applications(wi th sense). With my style of self learning, i hope it could be effective in JSP too....

I like to be advanced on the planned topic to be discussed by our instructor(He is not a certified Java Programmer though)

So now, all i know about JSP is the following:
-basic tags
expression <%= something%>
declaration <%! something%>
i dont know the term <% something %> I think it is an invocation
equivalent to java (Please correct me on that part)

-Setting up tomcat.
-The ROOT folder
-WEB-INF theoritically knew where to put classes/jars etc....
(though im not tested them yet)
-getting the value of a html form through request.getPara meter("form input-type name)

Those are basics obviously...( I learned them through surfing)

And im planning to create a simple application.
What comes on my mind is to reimplement my previous project (Simple Hotel FrontDesk System) into Online Hotel Reservation System
-the registration is obviously done by the hotel frontdesk only....
-Maybe the BlackList feature would be added if i knew the real ( Deep )

Actually, we have proposed a project "Online Entrance Exam" to our instructor and he likes it... so he approved our proposal.....( Not Thesis )

But before we start banging that project, deadline is on October ( Final week in this semester )

I like to grasp the essentials of JSP and also the other techniques, new way, and theory behind that architectural design for web application platform....
(Please correct me on the phrase above)

Actually, the faculty decided to order a J2EE book from Sun( i think the book base is in Singapore) for about 2500php or $56.00

Unfortunately, that book is expected to be arrived on midterms.... unbelievable scenario(but that was true)....

I did attempt to buy a new book instead of waiting that precious book, but i doubt for having such book....(for $40.99)....

So i decided to wait that precious book, yet learning in advance from this forum and the other web resources....

What a long story :)

Well, anyway,

Here is what i suppose to know in JSP as im building my experimental application for the supplement on my final project( Not thesis though )

I like to know about the JSP Beans,

for example, i have a java class that contains setter and getter methods,
i like to jar them, unfortunately, i didn't found the right tutorial for it on the web...

so can you post a helpful url that would teach me how to do that?
and also, about how to access the jar file from the jsp container( doubt of terms )Please correct me....

Or can you show an example?
For example, i have a jar file in WEB-INF/lib/JARZKY.jar
and the content is com\myclass.cla ss(with setSetter() and getGetter() methods)

How can you invoke that class through JSP?


A sincere Java Lover,
sukatoa
Jul 3 '08
35 3667
chaarmann
785 Recognized Expert Contributor
This is my first time to have IF/ELSE statements more than i've expected on a single file..........

Is it natural to have more if/else statement on just a single JSP file?
or can you recommend to me experts how to reduce such structure? ( URL )

Looking forward on your replies,
sukatoa
You can reduce such a structure by making a decision table. And put the long expression in a function!
Example (Wrong way):
[HTML]<HTML>
<FONT color=<% if(a==7) out. write("red") else {if (b==1) out.write("yell ow") else if (b==2) out.write("red" ) else out.write("gree n")}%> Hello World </FONT>
</HTML>[/HTML]
Example(Right way):
[HTML]<%!
private String getColor(int a, int b)
{
if (a==7 || b==2) return "red";
if (b==1) return "yellow";
return "green";
}
%>
<HTML>
<FONT color=<%= getColor(a,b) %> Hello World </FONT>
</HTML>[/HTML]


Just a sidenote:
Every if-else can be reduced to a formula. Fore example:
Expand|Select|Wrap|Line Numbers
  1. z=0;
  2. if (x=7) z=3; else z=5;
can be written as
Expand|Select|Wrap|Line Numbers
  1. z = (x=7) ? 3 : 5
or as a formula:
Expand|Select|Wrap|Line Numbers
  1. z =  Math.abs(Math.signum(x-7)) * 2 + 3;
The last expression evaluates to
case x==7 --> 0*2+3 --> 3
case x !=7 --> 1*2+3 --> 5
Aug 11 '08 #21
sukatoa
539 Contributor
What was the exact error message?
@ reply#16(mine), that error occured due to typo.......

@reply#17
Error fixed, yet the problem persist, only the Object type ArrayList when converted to String on JSP page, well i don't know the reason but not all values are set on the said bean........

Before i've come-up the alternative way, my bean has an Object-type ArrayList that stores all the String representation value from my sign-up form.....

In any time, all the values that i was trying to store on that bean from the validation.jsp fails, no error message issued...

My first approach was it is a known/unknown bug, then i tried to rewrite the type of that ArrayList into String instead of Object since all the values are Strings........

Here is my previous algo:
scope=session.

catch all values from the form through request.getPara meter() method
store them in a temporary String type ArrayList.

If there is an invalid input, blank or unmatched values, then erase the password, retypepassword, emailaddress,re typeemail and confirmation code values from that temporary String List and replace them with a value "invalid".
else, persist.

Convert the temp list into Object type List then upload to the bean.....

Redirect into the signup page to fill-up correctly all the necessary fields.

Initialize a temp String type arraylist and store all the values from the bean(Object type, assumed it was converted again down to String)

Now, here is the problem.

alternately, all values that was stored by the validation.jsp into bean is not exactly received by the signup form(JSP page)...... I've list down the behavior of the beans,

first attempt:
Lacking: username, creditcard number
second attempt:
Not exact: password & retypepassword
third attempt:
validation code
fourth attempt:
etc & etc.......

And before i click the submit button, i've wrote all the values exactly what my naked eyes could see.....

And, it appears that there is a problem on my inputs..(i've created an indicator that tells the guests about their wrong input/leaved blank)......

I get stuck on this experiment(last day). I've exert all of my efforts on debugging, and it is proven that there should be no error, typo, mistakes on my code.....

my last option was to use my common sense.
Since all the values are being treated as String and absolutely a pure string data type, then i've changed the Object type ArrayList into String type ArrayList.

Then it solves my problem......

You may not believe on this kind of scenario, but it really happens on my part.......





You can reduce such a structure by making a decision table. And put the long expression in a function!
Example (Wrong way):
[HTML]<HTML>
<FONT color=<% if(a==7) out. write("red") else {if (b==1) out.write("yell ow") else if (b==2) out.write("red" ) else out.write("gree n")}%> Hello World </FONT>
</HTML>[/HTML]
Example(Right way):
[HTML]<%!
private String getColor(int a, int b)
{
if (a==7 || b==2) return "red";
if (b==1) return "yellow";
return "green";
}
%>
<HTML>
<FONT color=<%= getColor(a,b) %> Hello World </FONT>
</HTML>[/HTML]


Just a sidenote:
Every if-else can be reduced to a formula. Fore example:
Expand|Select|Wrap|Line Numbers
  1. z=0;
  2. if (x=7) z=3; else z=5;
can be written as
Expand|Select|Wrap|Line Numbers
  1. z = (x=7) ? 3 : 5
or as a formula:
Expand|Select|Wrap|Line Numbers
  1. z =  Math.abs(Math.signum(x-7)) * 2 + 3;
The last expression evaluates to
case x==7 --> 0*2+3 --> 3
case x !=7 --> 1*2+3 --> 5
What always come to my mind is that "z = (x=7)? 3: 5"
But the methods are all created for validation only........

All conversion, db access, constants, encoders/decoders are in a bean.....
and all elseif statements are forcely implemented for validations.... ..
(my last option)

Like:

Expand|Select|Wrap|Line Numbers
  1. if this is, 
  2.     then do this, 
  3. else, 
  4.     do also this,
Unless, if it is an assignment operation with two options to choose with respect to its (logically tested)value, then this "z = (x=7)? 3: 5" pattern should be used.........

Thanks for the examples,
i will try it.....

JSP beginner,
sukatoa
Aug 11 '08 #22
chaarmann
785 Recognized Expert Contributor

What always come to my mind is that "z = (x=7)? 3: 5"
But the methods are all created for validation only........

All conversion, db access, constants, encoders/decoders are in a bean.....
and all elseif statements are forcely implemented for validations.... ..
(my last option)

Like:

Expand|Select|Wrap|Line Numbers
  1. if this is, 
  2.     then do this, 
  3. else, 
  4.     do also this,
Unless, if it is an assignment operation with two options to choose with respect to its (logically tested)value, then this "z = (x=7)? 3: 5" pattern should be used.........

Thanks for the examples,
i will try it.....

JSP beginner,
sukatoa
There is a mistying on my side, the corrected version is:
Expand|Select|Wrap|Line Numbers
  1. z = (x==7) ? 3: 5;
Please note the double-equal sign after "x", or else it will not work as intended.

My example with decision table and function should show you that instead of using:
Expand|Select|Wrap|Line Numbers
  1. if this is, 
  2.     then do this, 
  3. else, 
  4.     do also this,
it is better to use
Expand|Select|Wrap|Line Numbers
  1. if this is, 
  2.     then do this and return, 
  3. do also this,
This reduces complexity of your if-else nesting.
Please note that a "decision table" puts cases which are the same together, which also reduces your if-else-nesting.
Like in the example:
Expand|Select|Wrap|Line Numbers
  1. if this, then do that
  2. if this, then do also that 
is reduced to
Expand|Select|Wrap|Line Numbers
  1. if this or this then do that
.
This is just a simple part of this matter. There is a whole course at university only how to make decision tables and it can be a complex matter, but it is worth it. It makes your programs smaller (=faster) and easier to understand.
Aug 12 '08 #23
sukatoa
539 Contributor
Im just wondering.....

I have observed the behavior of my JavaServer Pages such that it will encounter an IllegalStateExc eption when this application not modified(not roaming around the site) for 20 to 30 mins(minimum).. .. (After logging-in)

Why?

Can this be avoided?
All of my beans are session scoped.....

Please let me know experts,
sukatoa
Sep 3 '08 #24
JosAH
11,448 Recognized Expert MVP
Im just wondering.....

I have observed the behavior of my JavaServer Pages such that it will encounter an IllegalStateExc eption when this application not modified(not roaming around the site) for 20 to 30 mins(minimum).. .. (After logging-in)

Why?

Can this be avoided?
All of my beans are session scoped.....

Please let me know experts,
sukatoa
On a Tomcat Servlet container a Session times out after 30 minutes (by default)
if I remember correctly. If you don't want that you should anticipate for it like
extending the timeout time for the Session object.

kind regards,

Jos
Sep 3 '08 #25
sukatoa
539 Contributor
thanks for your reply Jos,

But, how can i modify its default value?

Can you recommend me where to read that one?

regards,
sukatoa
Sep 4 '08 #26
chaarmann
785 Recognized Expert Contributor
thanks for your reply Jos,

But, how can i modify its default value?

Can you recommend me where to read that one?

regards,
sukatoa
If your page does not use session, you can use a jsp-directive. Just write at the top of your jsp-page:
Expand|Select|Wrap|Line Numbers
  1. <%@ page session="true" %>
If you want to use a session and want to modify its timeout (e.g. 4 hours=240 minutes), there are several ways.
1.)
write in your jsp-page:
Expand|Select|Wrap|Line Numbers
  1. <% session.setMaxInactiveInterval(240*60); %>
2.) write in your web.xml
Expand|Select|Wrap|Line Numbers
  1. <session-config>
  2.        <session-timeout>240</session-timeout>
  3. </session-config>
The file is there two times: in tomcat's "conf" folder (default value for all applications) or in your application's "WEB-INF" folder. (default value for all jsp-pages of your application)
Sep 4 '08 #27
r035198x
13,262 MVP
thanks for your reply Jos,

But, how can i modify its default value?

Can you recommend me where to read that one?

regards,
sukatoa

The place to read would be the Servlet Specification

You can change it for the whole application or for a particular session only.
When changing for the whole application then you set the value in your application's web.xml with something like

Expand|Select|Wrap|Line Numbers
  1. <session-config>
  2.     <session-timeout>100</session-timeout>
  3.   </session-config>
that is 100 minutes

For a particular session then that would be
int seconds = ....//your required timeout
Expand|Select|Wrap|Line Numbers
  1.  session.setMaxInactiveInterval(seconds);
Edit: Since when did chaar get a faster keyboard than mine?
Sep 4 '08 #28
sukatoa
539 Contributor
If your page does not use session, you can use a jsp-directive. Just write at the top of your jsp-page:
Expand|Select|Wrap|Line Numbers
  1. <%@ page session="true" %>
If you want to use a session and want to modify its timeout (e.g. 4 hours=240 minutes), there are several ways.
1.)
write in your jsp-page:
Expand|Select|Wrap|Line Numbers
  1. <% session.setMaxInactiveInterval(240*60); %>
2.) write in your web.xml
Expand|Select|Wrap|Line Numbers
  1. <session-config>
  2.        <session-timeout>240</session-timeout>
  3. </session-config>
The file is there two times: in tomcat's "conf" folder (default value for all applications) or in your application's "WEB-INF" folder. (default value for all jsp-pages of your application)
Thanks, that was interesting to read,
But, i have modified the web.xml in WEB-INF folder, and i couldn't see

Expand|Select|Wrap|Line Numbers
  1. <session-config>
  2.        <session-timeout>240</session-timeout>
  3. </session-config>
I expect that it was there, yet, it should be added.....

So, Here is the content of the web.xml

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!--
  3.   Copyright 2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17.  
  18. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  19.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  20.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  21.     version="2.4">
  22.  
  23.   <display-name>Welcome to Tomcat</display-name>
  24.   <description>
  25.      Welcome to Tomcat
  26.   </description>
  27.  
  28. <!-- JSPC servlet mappings start -->
  29.  
  30.     <servlet>
  31.         <servlet-name>org.apache.jsp.index_jsp</servlet-name>
  32.         <servlet-class>org.apache.jsp.index_jsp</servlet-class>
  33.     </servlet>
  34.  
  35.     <servlet-mapping>
  36.         <servlet-name>org.apache.jsp.index_jsp</servlet-name>
  37.         <url-pattern>/index.jsp</url-pattern>
  38.     </servlet-mapping>
  39.  
  40. <!-- JSPC servlet mappings end -->
  41.  
  42. </web-app>
Can you point me where to put your suggested xml code in the xml above?
This was my first time to modify such config file.....

P.S i just don't want to commit mistake specially on this type of file... because i believe that if there is something wrong with this, i can't trace whatever error/bug may exists later......

sukatoa
Sep 4 '08 #29
chaarmann
785 Recognized Expert Contributor
Can you point me where to put your suggested xml code in the xml above?
This was my first time to modify such config file.....

sukatoa
Inside your web-app element. (line 22)
Sep 5 '08 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2545
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already started sending out the content of the page. Web content is always delivered with a few headers at the top, ending with a blank line. For example, a web page might start like this:
1
2357
by: soni29 | last post by:
Hi, I'm going to be starting a project with a friend of mine in C#, we're doing it to learn the language a little better, to get more experience with it. We've already come up with an idea of the application to build, but need advise on how to get started, to share the work? Also if there are free servers available with sourcesafe, so we can use that, and just any basic advise on getting started, how to split work. Thank you.
0
1533
by: cara_little | last post by:
Good Morning, I'm trying to get started with the Enterprise Library to evaluate it and recommend to the rest of the developers in the company. However, I'm having a heck of a time getting started and must be missing something. All of our development is completed in VB. I have installed Enterprise Library on my machine - however I can't compile the project. Is the code only available in C#? which means I have to have C# installed just to...
0
1706
by: tamdino | last post by:
Please accept my apologies if I am posting this in the wrong place. I am trying to get started using MySQL-Front and I am totally lost. Does anyone know where there is a tutorial for getting started with this interface? Thanks, Tammy
84
3954
by: Bibby | last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled in C, C++ and VB6. Which would be the best language to focus my attention to regarding the following considerations: Hireability Portability Flexibility The likely candidates seem to be Java, VB.Net, C, C++, C#.
6
2188
by: Jack Duijf | last post by:
Hello, I am looking for a person in The Netherlands that is willing to help me getting started with Vb.net. Please send a message to jack@aicn.nl if you can help me getting started with the Microsoft Developement Enviroment. Thanks,
1
4747
by: =?Utf-8?B?Q29kZVNsaW5nZXI=?= | last post by:
I plan to build my own 2008 Server/Hyper-V system and will not be using one of the tested Dell or HP systems from the release notes and could use some pointers as to my assumnptions and answers to a few questions. Some getting started with Hyper-V assumptions. Please tell me if I am off base here. 1. Any recent Intel quad core processor has the needed x64 architecture with hardware assisted virtualization and data execution protection...
0
9640
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10520
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10196
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6940
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5614
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5774
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.