I'm bored at work

Sep 29, 2004
18,656
67
91
Originally posted by: MrYAK
give me something to look up and i'll tell yall about it.

I'm also bored. Tell me everything I need to know about developing a web page in JSP. Anything you want to know?
 

Pastore

Diamond Member
Feb 9, 2000
9,728
0
76
Originally posted by: IHateMyJob2004
Originally posted by: MrYAK
give me something to look up and i'll tell yall about it.

I'm also bored. Tell me everything I need to know about developing a web page in JSP. Anything you want to know?

He is either getting yelled at by his superior for screwing off at work, or is learning all he can about JSP for you, lol.
 

MrYAK

Senior member
Aug 19, 2004
826
0
0
Originally posted by: IHateMyJob2004
Originally posted by: MrYAK
give me something to look up and i'll tell yall about it.

I'm also bored. Tell me everything I need to know about developing a web page in JSP. Anything you want to know?

yeah acctualy, why does the general population think that what someone famous says/does/wears/owns is the the way everyone should do it. and why in magazines do they back this up? why do most ppl care why *this famous person* is doing this or whatnot. why cant someone with common sence, like me, go on national tv and say, "hey, who fvcking cares what these ppl do? dont you have yer own life?" why are we, the general population, so material driven? so you have $50mililon dollars, do you really need 40br house and 6 cars?

hmmm, looks like i started to rant a little there...sry about that. but why is the question i'm looking for.
 

MrYAK

Senior member
Aug 19, 2004
826
0
0
Originally posted by: IHateMyJob2004
Originally posted by: MrYAK
give me something to look up and i'll tell yall about it.

I'm also bored. Tell me everything I need to know about developing a web page in JSP. Anything you want to know?

ok, so i did some research, took some notes, and learned my self some JSP. since i have no clue about JSP, i though i would take the time and put together this little number i like to call, "Hey, just copy paste it. The run through that is JSP " by MrYAK-




The Different Varieties of Tag
Let's begin by looking at the different kinds of tag that can be found in a JSP.

DIRECTIVES

Directives are instructions that are processed when the page is compiled. They begin with <%@ and end with %>. Examples are the <%@ page %> and the <%@ include %> directives.

HIDDEN COMMENTS

These are used to document the page and are not sent to the client. The form is <%-- comment --%>. Any characters may be used in the body of the comment except the closing "--%>" marker which should be escaped as "--%\>".

DECLARATIONS

These are used to declare variables or methods that have scope throughout the page. The opening tag is <%! and the closing tag is %>. For example:

<%! String strMyString = "hello";

private void doSomething() {
//
}
%>

EXPRESSIONS

The result of an expression is cast to a String and inserted into the output stream at the place where it occurs. The form is <%= expression %>. For example:
<%= strMyStringVariable %>
<%= getData() %>
Note that the expression is not terminated with a semicolon. This is because the parser simply wraps an out.print() or similar around the expression, and a colon will produce a compiler error (the second example would be parsed to "out.print(getData(););", which is invalid). The expression can appear anywhere within the HTML of a page. For example:

<INPUT TYPE="TEXT" NAME="COUNTRY" VALUE="<%= strCountry %>">

Expressions can sometimes be used as attribute values within JSP elements. You should consult the API reference for details.

SCRIPTLETS

Scriptlets are code fragments that can contain any valid code enclosed between <% and %>. Code here can access any declared variable or bean, and is executed at request time. A typical use of a scriptlet is to wrap a conditional or a loop around a block of HTML. An example:

<% if(request.getParameter("user").equals("new")) { %>
<B>Please sign up!</B>
<% } else { %>
<B>Welcome back!</B>
<% } %>

The output will vary depending on the value of the request parameter. Note the use of the implicit request object which does not need to be declared. Here is an example that combines scriptlets and expressions:

<% for(int i=1; i<11; i++) { %>
The current number is: <%= i %><BR>
<% } %>

ACTIONS

There are also a number of XML-type tags that begin with "<jsp:" and are sometimes called "actions". Some of these will be explored below.

The Main Tags
Rather than exhaustively list all tags and attributes we will instead focus on some of the main aspects. In fact, if you consult Sun's JSP documentation, you may be surprised at how just little there is to the API.

<%@ page %>

At the top of each JSP is the page declaration. Here is an example:
<%@ page
language="java"
import=". . ."
errorPage=". . ."
contentType=". . ."
%>

At present only the Java language can be used in a JSP, so the language attribute should be as shown. The import attribute contains a comma-delimited list of packages or classes to import for the compiler. The errorPage attribute is interesting - it is the path to a page to which the client is redirected when an exception occurs. The error page can use the built-in exception object to decide what to display to the user. The contentType attribute is self-explanatory.

<jsp:useBean> and <jsp:setProperty>

Here is an example of how to set up a bean instance in a JSP:

<jsp:useBean
id="beanInstanceName"
scope="page|request|session|application"
class=". . ."
>
<jsp:setProperty
name="beanInstanceName"
property="propertyName" value="theValue"
/>
</jsp:useBean>

The JSP engine will look for a bean instance that matches the scope. If it cannot find one it will instantiate a new one using the no-argument constructor. The id attribute is the name of the variable to use for referencing the bean within the page. The scope attribute is very important and has the following values:

page

The bean can be used within the page until the client response is sent.

request

The bean can be used in any JSP that is processing the same request.

session

The bean can be used in any page that participates in the client session.

application

The bean can be used in any page in the current application.

One important use of beans is to store data between client requests. Depending on the usage, if you do not set the right scope attribute you may produce an unecessary performance hit. An example is a bean that contains a HashMap of data that is fetched from an updated file every few minutes, such as an FTP news headline or stock price feed. The scope of the bean should be set to "application" for optimal performance, since a new instance is not required for each client request.

The <jsp:setProperty> is used to set the value of a bean property using its SET methods. A useful shortcut is to use an asterisk for the property attribute: property="*". This will take all of the client request parameters which have the same name as a bean property and set them all in one go, performing type conversion if necessary.

<jsp:getProperty>

This tag retrieves the value of a bean property and displayes it in the page. However it cannot handle indexed bean properties. The format is:
<jsp:getProperty name="beanInstanceName" property="propertyName"/>
The name atribute points to the bean with the same id attribute in the <jsp:useBean> tag, and the property attribute is the name of the bean property you wish to display (it must have a corresponding GET method in the bean).

<%@ include %>

This directive inserts the contents of a file into the JSP at compile time. The text becomes part of the JSP page. It is useful for including code that is common to a number of pages, but for which you do not want to use a bean. The format is:
<%@ include file="relativeURL" %>

<jsp:include>

This tag is used to include either static or dynamic content in the output stream. If the file is dynamic, you can use the <jsp:param> tag to pass parameters to it. For example:

<jsp:include page="/login.jsp">
<jsp:param name="username" value="Fred"/>
</jsp:include>

It is important to distinguish between the <jsp:include> tag and the <%@include %> directive. The former is for including content at request time, whereas the latter should be used for static content at compile time.

<jsp:forward>

This tag takes the implicit request object (which contains the client request parameters and other CGI-type data) and forwards it to a target file which can either be an HTML page, a servlet, or another JSP file. The target must be in the same application context. For example:
<jsp:forward page="relativeURL|<%= expression %>">
<jsp:param name=". . ." value=". . ."/>
</jsp:forward>
The <jsp:param> tag is used to pass additional parameters to the target. Note the way in which the tag is closed at the end - this is standard XML. This <jsp:forward> is also an example of a tag that can contain an expression as a part of it.

Java Server Pages are a simple yet powerful way of developing dynamic server-side applications, and are rapidly becoming the system of choice for many web developers due to their ease of use and their separation of presentation and functional logic through the use of bean components.




So in short, if this dont help, read this book HERE, good read:thumbsup:

**EDIT**
LOL, it made emotes! my plan WORKED!!