Register | Log in | Password |

365 projects | 71 services | 215 websites | 1073 freelancers | 2762 topics | advertise


Purchase JoomlaWatch:
30 day money-back guarantee
Read more...
9 EUR lifetime license
Buy Now

15 EUR lifetime license
Buy Now
(nofollow link from sponsors page)

Login:

23%United States United States
15.7%India India
7.3%Russian Federation Russian Federation
7%Colombia Colombia
6.1%Germany Germany
5.2%United Kingdom United Kingdom
4.4%Poland Poland
3.4%Netherlands Netherlands
3%France France
2.8%Canada Canada

Today: 730
Yesterday: 1639
This Week: 3955
Last Week: 10059
This Month: 10654
Total: 33968

Users

Most active users today from total of 27:
matto, rottenberg, dontbugmeplease, Adelavigne, eghtedar, manuelflores, rockiesrider, michmich, infomech, Andii S., jacek2011, Me2, iwm, mirkogeo, sstinfo, texa, stecho, rifki, openaspace, blombo
About JoomlaWatch:
JoomlaWatch is popular joomla visitor tracking and live stats component. It provides several features such as spam blocking, goals tracking, charts, nightly email reports, latest visit map, interactive HTML5 traffic flow graph and many other useful functionalities, which will help you to optimize your site.
RSS Feeds:

rss Freelance
rss Projects
rss Forum
rss Resources

Home

JSP and Servlet Tips

Here are some of my notes from HTML, Servlets, JSP Course:

Servlets

getPathInfo() - path in URL

getPathTranslated() - where the filename is located


Setting the header

response.setHeader("Content-type","es");

utility native2ascii - converts native codepage to UTF-8 encoding. Useful for .property files and localization


Global attributes


this.getServletContext().setAttributes("name", value);
- attribute that is visible in the whole application.. for more servlets



JSP

<%-- comment
<%! - declaration (it stores the code out of the service method)
<%@ - directive (affects translation of JSP to Servlet, compilation.. useful for tuning for specific cases like setting the error page, code page imports, etc.)

XML syntax of JSP page:
... - same as <%!

include

<%@ include file='file.jsp" %>
includes file to a page (before translation)
- don't recognize if the included file has changed
- includes all of the parameters or attributes for included page


or

< jsp:include page="file.jsp" >

dynamic include (during the processing of main page), more flexible
- this way we can include result of server or other JSP page
- explicit parameter passing to included page by < jsp: param name="name_of_parameter" value="value_of_parameter"> tag.
for included pages, there is a need for inserting pages without HTML < body > types !


The page directive

<%@ page ... % >

useful for setting additional properties for jsp page like isErrorPage="true|false"

plugins

usage:
< jsp:plugin >
...

< /jsp:plugin >

it inserts Java applet to the page


System environments

usage:

TERM=vt100

java -D user.term=$TERM

then, we can access this environment variable by:

System.getProperties() - it returns instance of class Property.
System.getProperties().getProperty("user.term");

System.getProperties().remove("user.term");

JavaBeans

requirements for JavaBeans:

- there have to be set/get methods specified
- has to have public default constructor (without parameters)
- it should be in a package
- serializable
- get/set methods has to have the same data type!
- bean cannot modify content of a page!


... in general, JavaBean is a standard Class.

It can be used as a simple component in a JSP page.

- get method has to be fast, and it should be plain and simple.

usage in a JSP page:

< jsp:useBean id="nameOfBean" scope="session" class="myPackage.Counter" />

< jsp:getProperty name="nameOfBean" property="myCount" />

this is the same as

<%= Counter.myCount %>

with JSTL Expression language:

< c:out value="${Counter.myCount}" >

automatically set the bean attributes from from names (!important!):
< jsp:setProperty name="pocetMiest" property="*" />




scope can be:

application - the bean is available in all application, when that's in more JSP pages, one of them can create it once and other JSP pages can use it. It's something like a global object for all application.

session
- stored data, just for this session

request
- just for request or forward

page
- smallest scope, just on a page that is called (forwarded or included)


Custom Tags


- reusability
- components which you can download and use on your JSP page (3rd party)
- Custom tags can also command the pageflow instead of JavaBean, you can for example terminate a page by some custom tag.

eg. mytaglib.tld - containts a descriptor of tags in XML

usage:


< %@ taglib uri="/WEB-INF/jsp/mytaglib.tld" prefix="first" % >
some text ....

or

< %@ taglib uri="mytaglib" prefix="first" % > -> mytablib has to be defined in web.xml
- advantage: when changing a tag library, it can be changed only in web.xml instead of changing it manually in every file.

< first: something />

some text ....


< first:something name="myAttribute" value="myValue" / > -> has to be defined in mytaglib.tld !

in tld file:
- < rtexprvalue >true|false< /rtexprvalue > - says that we can use in params < %= expression % >
eg.:
< first:something name="myAttribute" value="< %= expression % >" / >

writing Custom tag class:


- imports javax.servlet.jsp.tagext.*;
- class has to implement class Tag or has to extend TagSupport
class

method doStartTag() - method that is executed when there is a occurency of a start tag.

pageContext.getOut.print("I will print this"); // in try/catch block



method doEndTag() - method is executed when there is a closing tag.

method getParent() - returns a parent of a current tag;

method release() - there we can release some system resources, etc.

when there is a body of a tag, it has to implement BodyTagSupport instead of simple TagSupport
it means, that you can nest multiple tags within the tag content.

method doAfterBody() - for handling nested content

BodyContent bc = getBodyContent(); // content of a tag body

String body = bc.getString(); // convertion to a String

JSPWriter out = bc.getEnclosingWriter(); // enclosing writer of the parent tag.. result can will be written there.


possible return values on the end of a tag handling method :

return SKIP_BODY; (ignores the body of a custom tag in JSP) - skip to handling method doEndTag()

return SKIP_PAGE; - skips the entire following content of a page.

return EVAL_BODY_TAG; - evaluates the body of a tag

return EVAL_PAGE; - we can continue in page evaluation


JSTL (Java Standard Tag Libraries)

- useful tags for creating cycles, we can elliminate scriptlets,
- formating messages
- internalization
- database communication
- expression language

expression language

- eases the manipulation with JavaBeans: eg. ${beanName.propertyName}
- allow you to evaluate given expression: eg. ${3+5}
- ${param["foo"]} - HTML parameters from query string
- ${cookie["myName"]} - cookie with name myName


JavaServer faces

- UI components for HTML
- saving it's state between calls
- we can work with beans on a server
- component model for HTML
- quite new technology
- implements MVC(model / view / controller) pattern as known as Model 2




Sending e-mail


package sun.netsmtp.SmtpClient;


SmtpClient smtp = new SmtpClient("...IP..");
smtp.from(from);
smtp.to(to);
PrintStream msg = smtp.startMesage();

msg.println(....);

smtp.closeServer();

- attachments cannot be inserted


JavaMail API

- more complex



- XSD is exchange for DTD

 

Add comment


Security code
Refresh


no license? questions?

Recommended: (advertise)
Joomlawatch 1.2.17 Demo (PRO: 9/15 EUR)
Download Joomlawatch 1.2.17 (PRO: 9/15 EUR)



Rate this extension ...


Stay in touch:

New online JoomlaWatch demo available here: (link)
5 hours ago from web

New comprehensive article on JoomlaWatch goals: (link)

JoomlaWatch is now available for Drupal as unlocked BETA version for testing: (link)
3 days ago from web

New article about JoomlaWatch Live Stats feature: (link)
5 days ago from web

Tested versions 1.2.12 FREE, 1.2.17 PRO, 1.2.18 BETA on Joomla 2.5 and older Joomla 1.5 - confirmed to work on both Joomla versions
2 weeks ago from web

Small installer fixes - added JoomlaWatch compatibility with Joomla 2.5
2 weeks ago from web

New article on JoomlaWatch Traffic Flow feature: (link) ... All features of JoomlaWatch will be documented this way.
2 weeks ago from web

Another minor fixes for version 1.2.17 and 1.2.18, added functionality to display only changed values in SEO report - important keyprases
2 weeks ago from web

Minor fixes for JoomlaWatch version 1.2.17 (language files), you can find the latest package in customer zone ((link)
3 weeks ago from web

If you'd like to help with testing of the latest 1.2.18 BETA with new features (Joomla/Wordpress),please add me on skype: matto3c.Thank you!

New article on JoomlaWatch SEO (Search Engine Optimization) report functionality - (link)

JoomlaWatch 1.2.18 is out now! Features new click heatmap feature, SEO report - how people find you on google, and many other improvements

Reorganized the menu items. Now you'll be able to easily find most requested links

JoomlaWatch 1.2.18 BETA now ready! Main features: - Heatmap integration - SEO reports - Anti-spam section visualization (link)

Fixed one issue: no unique visits recorded; PHP $_SERVER['REMOTE_ADDR'] doesn't always return remote IP address! using HTTP_X_FORWARDED_FOR

Christmas Special - 19% OFF from all licenses until 25th of December 2011

JoomlaWatch Heatmap functionality nearly done. Works with all client resolutions. Will be available in next version. (link)

Simple customer zone - (link) is now ready. Users who purchased the PRO version can now download newest version from there.

Because of the problems with payments and forwarding. We are using (link) service to deliver you the files after purchase.

Tracking Expenses from SMS android application is now published on android market :) and it's completely free !



Partners:
Freelance ColdFusion, Flex, PHP

Olejomalby, abstraktne obrazy

Camping Europe

WinAsm Studio

Vyšné Ružbachy

Sochy, Reštaurovanie

R.E.M.

Valid XHTML 1.0 Transitional

RSS feed:

Statistics:
Search Engine Genie Promotion Widget
Privacy policy | Advertise | Donate

Locations of visitors to this page


©2003-2010 Codegravity.com