The aim of this thread is to gather useful information in regards of Java web development. If you know some tips and tricks, tutorials or any interesting links that has not been already mentioned in previous posts please share with us (please always check to avoid double posting).
Please DO NOT post questions in this thread and also to not post any links leading to websites associated with you as this will goes against forum policies.

What you need for Java web development:Some previous Java knowledge, if you don't know Java you better start reading Starting "Java" [Java tutorials / resources / faq]
Installation of Java (instructions here)
Installation of either Java web server also know as J2EE server(JBoss, WebLogic, WebSphere) or web container (Tomcat, GlassFish) - [Quick jump to post here]
Access to database (MySQL, Oracle, HSQLDB etc.) - [Quick jump to post here]
Optional tools (Ant, Maven, Subversion) - [Quick jump to post here]
Your favourite IDE (IntelliJ IDEA, Eclipse, NetBeans, etc.)
Installing Java
Ubuntu
Install

sudo apt-get install sun-java6-jdk

Java is installed under /usr/lib/jvm/java-6-sun-1.6.0.15 (version number 1.6.0.15 my change over time)Note please that there been some changes in recent release of Ubuntu 10.04. To install Java you need first make changes in repositories as follows before you can run above installation command

sudo add-apt-repository “deb http://archive.canonical.com/ lucid partner”
sudo apt-get update

Set environment variable
Many tutorials on the internet will tell you that to set environment variable you need to only type EXPORT command followed by variable name and a path associated with it in your command line/terminal, but they fail to mention that this is only temporary measurement. To make your environment variable permanent in your system you need to edit bashrc file.

sudo gedit ~/.bashrc
//add at the end of the file
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.15
export PATH=$PATH:$JAVA_HOME/bin

Test

java -version
echo $JAVA_HOME
echo $PATH

Windows XP
Download latest installation package from here at the time of writing this entry it was JDK 6 Update 17. Double click and follow installation instructions (may want to uncheck the option for installing additional tool bars for browsers).
Set environment variables
Start > Control Panel > System or just press Window key(left down between Ctrl and Alt) + Pause/Break(up right at the end of F1-F12 row) and you will get System properties window. Here select Advanced tab followed by Environment Variables button. In system variables you should already have existing entry for PATH so click Edit and append ;C:\Program Files\Java\jdk1.6.0_16\bin pressOK. Now press New and in Variable name type JAVA_HOME and in Variable value type C:\Program Files\Java\jdk1.6.0_16 and press OK.
Test

java -version
echo %JAVA_HOME%
echo %PATH%

BOOKS Head First Servlet & JSP (2nd Edition) is great place to start. It will not show you how to build killer web applications, but it will provide will solid understanding of the basic need to successfully start development of web applications. This book is also recommended reading as part of preparation for Sun Certified Web Component Developer ( SCWCD )
Pro JSP 2 is another great book that will show you some additional Java web technologies like JSTL, JSF and Struts. Plus on top of that you have opportunity to learn something about security, performance, scalability and some recommendations of best practices
For fast learners there is also Beginning JSP, JSF, and Tomcat Web Development: From Novice to Professional
If you have already some knowledge of JSP and servlets you may want to broad your general knowledge of web frameworks have look at Art of Java Web Development: Frameworks and Practices
Starting Struts 2 (if you register with InfoQ)
Online Your First Cup: An Introduction to the Java EE Platform , very fast introduction by Sun (may not be suitable for everyone)
The Java EE 6 Tutorial, Volume I is full web development tutorial provided by Sun that will take you trough various topics (The Web Tier, Web Services, Enterprise Beans, Contexts and Dependency Injection for the Java EE Platform, Persistence, Security and Java EE Supporting Technologies). This very extensive reading.
javapassion.com provides access to numerous free courses related to Java or technologies that can be used alongside of Java
coreservlets.com These training materials are based on Marty's books Core Servlets and JavaServer Pages, More Servlets and JavaServer Pages, and Core Web Programming, and various online tutorials and conference talks.
IBM technical library
Hibernate - Getting Started
HIBERNATE - Relational Persistence for Idiomatic Java
Hibernate Reference Documentation
Apache Struts
Developing a Spring Framework MVC application step-by-step

~s.o.s~ commented: Finally! More "powah" to you, good job. ;-) +13
harry010 commented: hey. Thanks for all of the links to other resources. very helpful +1
SagarSe7en commented: another helpful tutorial by one of the geniuses of daniweb. Will recommend it to others :-) +2

Installing Tomcat
WARNING: You need to have JAVA_HOME variable set correctly or Tomcat will complain under any operating system.
Ubuntu
Download latest package from http://tomcat.apache.org , at the time of writing this the latest was Tomcat 6.0.20 and I used core binary distribution with "tar.gz" file extension.
Unpack

sudo tar zxvf apache-tomcat-VERSION_NUMBER.tar.gz

Copy to desired location

sudo cp -R apache-tomcat-VERSION_NUMBER /home/peter/tomcat6
//or move freshly extracted folder
sudo mv apache-tomcat-VERSION_NUMBER /home/peter/tomcat6

Change access permissions from root to me

sudo chown -R peter.peter /home/peter/tomcat6

First time test
Start Tomcat

/home/peter/tomcat6/bin/./startup.sh

Stop Tomcat

/home/peter/tomcat6/./shutdown.sh

and you will see something like this
[img]http://geni.maxgigapop.net/twiki/pub/GENI/AggMgrDeploy/apache-tomcat-startup.png[/img]
If this worked, well done, now you only need to set user and some optional things which you can find bellow Tomcat on Windows instructions, labelled as Tomcat configuration tips.


Windows XP
Download latest package from http://tomcat.apache.org , at the time of writing this the latest was Tomcat 6.0.20 and I used core binary distribution with "zip" file extension.
Unpack, with WinRAR, WinZIP or similar package (Please try to avoid Windows provided extraction software, it does strange thinks to packages). I like to keep it at hand so it can be easily location like this good idea C:\Tomcat6.0.20 .
Running Tomcat
You can start and stop Tomcat by double clicking on startup.bat and shutdown.bat respectively, but that is not wise thing to do. You better to start and stop it by calling these files from Command Prompt

cd C:\Tomcat6.0.20\bin
startup
shutdown

As you see this does require you to go down to actual "bin" folder of Tomcat wherever it is, but by creating new environment variable CATALINA_HOME with assign value of C:\Tomcat6.0.20 you can use following command respectively

%CATALINA_HOME%/bin/startup
%CATALINA_HOME%/bin/shutdown

Tomcat configuration tips
Setting Tomcat user and roles, you need to edit tomcat-users.xml file.
Ubuntu

gedit /home/peter/tomcat6/conf/tomcat-users.xml

Windows XP
Use either your IDE or any text editor beside Notepad.
You need to create a new role and new user as follows (Actual username and password value is your decision)

<tomcat-users>
    <role rolename="manager"/>
    <user username="admin" password="pass" roles="manager"/>
</tomcat-users>

Turn on servlet reloading - no need to restart server every time servlet is recompiled that has already been loaded in the server memory. For that you need to edit context.xml in same folder as previously edited tomcat-users.xml

//Change from
<Context>
//to
<Context reloadable="true" privileged="true">

Enable invoker servlet - if you are on the "fast-track" and have no time to edit deployment descriptor (web.xml file in TOMCAT_DIRECTORY/webapps/YOUR_PROJECT/WEB-INF) you need to edit web.xml in same folder as tomcat-users.xml
so new servlet deployed in YOUR_PROJECT/WEB-INF/classes can be called from browser by URL http://localhost:8080/YOUR_PROJECT/servlet/ServletName . You need to remove comments around these sections

<!-- Lines 122-132 -->
    <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

<!-- Lines 374-377 -->
    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>

To find "maveric instance under *unix system use following command

netstat -napt | grep 8080

JBoss to follow shortly

Books

Online

DATABASES

MySQL
Ubuntu
Install

sudo apt-get install mysql-server

During the installation process you will be asked to create "root" password. Just ignore it and we will set it up at the end.
Root password set-up

mysqladmin -u root password YOUR_PASSWORD
sudo /etc/init.d/mysql restart

Start/Stop MySQL

sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop

Access and leave MySQL

mysql -u root -p
//and after that you will be prompted for password
quit;

Windows XP
Download a copy of MySQL Community Server from http://dev.mysql.com/downloads/mysql (I normally use Windows essential option and cannot really say what extras you get with MSI installer).
Install
Welcome to the Setup Wizard for MySQL Server >> Next > Typical >> Next >> Install.
After installation go Next through all the screens of MySQL products presentation till you reach Wizard Complited where it will tell you can configure server in next step. Uncheck registration and leave only Configure Server option checked, press Finish. On new screen press NExt, select Standard Configuration, press Next. On this screen check Install As Windows Service, Include Bin Directory in Windows PATH.
You may want to uncheck Launch the MySQL Server automatically if you will not use database too often. On next screen provide password for "root" user press Next. On last screen you just need to approve action for configuration to take place and all is set.
By default MySQL server will start-up on each computer start-up which may not be desirable so if you wish you can change this behaviour through Administrative Tools (this Windows option is not always available in Start menu so you may want to add like here or just go Start > Run > type control admintools). Once the instruction following after this are executed you will need to start MySQL from Services manually each time you want to use it, so consider how often you will use database and choose appropriate scenario. In Administrative Tools you need to open Services option, find MySQL > right click > Properties > and change Startup type from Automatic to Manual.
Use MySQL
If you ticked checkbox during installation to add MySQL to PATH you can call upon database (as long you have it running) from Command Prompt by executing

mysql -u root -p
//followed by prompt for password

To make it even faster and easier Windows installation comes with MySQL Command Line Client that can be found through Start menu and will automatically execute first command from above and will only ask you for password.

MySQL add-on
If you are not command prompt/line junkie and wish to use some graphical interface you can download MySQL GUI Tools.
Ubuntu

sudo apt-get install mysql-query-browser

Run MySQL GUI Tools
Applications > Programming > MySQL Queury Browser

Windows XP
Download it from http://dev.mysql.com/downloads/gui-tools and install it.

Postgres

Ubuntu
Install Postgresql

sudo apt-get install postgresql

change default password

sudo -u postgres psql postgres
\password postgres

Enter new password 2x


Following steps allows you to set remote access

sudo vi /etc/postgresql/8.4/main/postgresql.conf

EDIT

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

#listen_addresses = 'localhost'

TO

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'

Then edit

sudo vi /etc/postgresql/8.4/main/pg_hba.conf

add following line to enable access from IP 81.149.251.48 of subnet mask 255.255.255.254

host all all 81.149.251.48/31 md5

And change security mechanism (useful for example when restoring database from backup file)

local   all         postgres                          indent

to

local   all         postgres                          md5

AFTER THIS RESTART IS NEED IT

sudo /etc/init.d/postgresql-8.4 restart

Posgres have also handy GUI that can be installed for
Ubuntu

sudo apt-get install pgadmin3

Oracle
To follow shortly

HSQLDB
Available for download http://sourceforge.net/projects/hsqldb/files/
User guide http://hsqldb.org/web/hsqlDocsFrame.html
How-to/FAQ http://hsqldb.org/web/hsqlFAQ.html

SQLite
Available for download http://www.sqlite.org/download.html
Documentation http://www.sqlite.org/docs.html

Common database connection strings

MySQL (MM.MySQL Driver)
jdbc:mysql://<HOST>:<PORT>/<DB>
org.gjt.mm.mysql.Driver

Oracle Thin
jdbc:oracle:thin:@<HOST>:<PORT>:<SID>
oracle.jdbc.driver.OracleDriver

PostgreSQL (v6.5 and earlier)
jdbc:postgresql://<HOST>:<PORT>/<DB>
postgresql.Driver

PostgreSQL (v7.0 and later)
jdbc:postgresql://<HOST>:<PORT>/<DB>
org.postgresql.Driver

IBM DB2
jdbc:db2://<HOST>:<PORT>/<DB>
COM.ibm.db2.jdbc.app.DB2Driver

JDBC-ODBC Bridge
jdbc:odbc:<DB>
sun.jdbc.odbc.JdbcOdbcDriver

Microsoft SQL Server
jdbc:weblogic:mssqlserver4:<DB>@<HOST>:<PORT>
weblogic.jdbc.mssqlserver4.Driver

Microsoft SQL Server (JTurbo Driver)
jdbc:JTurbo://<HOST>:<PORT>/<DB>
com.ashna.jturbo.driver.Driver

Microsoft SQL Server (Sprinta Driver)
jdbc:inetdae:<HOST>:<PORT>?database=<DB>
com.inet.tds.TdsDriver

Microsoft SQL Server 2000 (Microsoft Driver)
jdbc:microsoft:sqlserver://<HOST>:<PORT>[;DatabaseName=<DB>]
com.microsoft.jdbc.sqlserver.SQLServerDriver

//To test your driver once it's installed, try the following code:

Class.forName("Driver name");
Connection con = DriverManager.getConnenction("jdbcurl","username","password");

Books

Online

Tools
There numerous tools used in the industry and soon or latter you will face them. So bellow is quick installation guide for installing some of them

ANT
Ubuntu
Install

sudo apt-get install ant ant-optional

Location of where ANT been installed sometimes change across on different versions, so you better check it out before setting environment variable

ant -diagnostics

and look for section marked ANT Properties you will find ant.home value
Set environment variables

sudo gedit ~/.bashrc
//Add path to ant recovered in previous step in my case /usr/share/ant
export ANT_HOME=/usr/share/ant
//Append to path
export PATH=$PATH:$ANT_HOME/bin

Windows XP
Download from http://ant.apache.org/bindownload.cgi . Extract it in convenient location (In my case C:\Ant-1.7.1 ).
Set environment variables
(Check Java Windows XP steps if you do not know where to set environment variables.) Create new variable ANT_HOME with value C:\Ant-1.7.1 and append PATH with ;%ANT_HOME\bin Maven
These are steps to set Maven 2

Ubuntu
Install

sudo apt-get install maven2

Set environment variables

sudo gedit ~/.bashrc
export M2_HOME=/usr/share/maven2
export M2=$M2_HOME/bin
//Append to path
export PATH=$PATH:$M2
//Optional allocation of extra memory
export MAVEN_OPTS="-Xms256m -Xmx512m"

Windows XP
Download from http://maven.apache.org/download.html . Extract it in convenient location (In my case C:\Maven-2.2.1 ).
Set environment variables
(Check Java Windows XP steps if you do not know where to set environment variables.) Create new variable M2_HOME with value C:\Maven-2.2.1 , new variable M2 with value %M2_HOME%\bin , append PATH with ;%M2_HOME%\bin and you can also provide optional memory allocation with new variable MAVEN_OPTS and value of -Xms256m -Xmx512m .m2 directory is used to store your settings.xml containing various info from declarations of library dependencies and custom repositories, plus more. This can be created by executing

mvn clean install

Location under Ubuntu Location under Windows XP C:\Documents and Settings\Peter\.m2 Subversion
Ubuntu

sudo apt-get install subversion

Windows XP
Download one of the Subversion packages here ( I'm using Tigris.org on my Windows machine), run the installation and follow on screen messages.

Some simple commands
Create local repository

//Ubuntu
sudo mkdir /home/peter/svn-repos
sudo svnadmin create /home/peter/svn-repos
//Window
mkdir C:\svn-repos
svnadmin create C:\svn-repos

Checkout code to local repository

//Ubuntu
svn checkout http://open.jira.com/svn/PEBBLE/trunk /home/peter/svn-repos/PEBBLE
//Windows
svn checkout http://open.jira.com/svn/PEBBLE/trunk C:\svn-repos\PEBBLE

Check status of your local repository

svn status

Update your local copy

svn update

Commit changes

svn commit -m "Comment to accompany these changes"

Books

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.