Follow me step-by-step to build a JSP environment under Linux Platform

Source: Internet
Author: User
Tags mkdir postgresql version tomcat linux
JS can knock me tired ah, oh, can't find the whole of the document, on their own wrote a, let me like the rookie door Easy point:). This article only uses Tomcat to write the program, does not do the server environment, therefore does not integrate Apache.

Environment: RedHat AS3

JDK Installation path:/USR/JAVA/JDK

Tomcat Installation path:/usr/local/tomcat/

A total of the following steps are divided:

First, install the configuration JDK

Second, install the configuration tomcat

Iii. installation of PostgreSQL

Four, Tomcat test

V. Connecting to the Database

The software you need:

J2sdk-1_4_2-linux-i586-rpm.bin

Jakarta-tomcat-4.1.30.tar.gz

postgresql-7.4.1-1pgdg.i386.rpm

postgresql-jdbc-7.4.1-1pgdg.i386.rpm

postgresql-server-7.4.1-1pgdg.i386.rpm

postgresql-libs-7.4.1-1pgdg.i386.rpm

All of these software are/download in a backup.

#mkdir?/download

1. Installation Configuration JDK

Download Address: http://java.sun.com/j2se/1.4.2/download.html

Download the RPM package, which is actually a. bin file

#chmod? u+x?j2sdk-1_4_2-linux-i586-rpm.bin

#./j2sdk-1_4_2-linux-i586-rpm.bin

#rpm?-ivh?j2sdk-1_4_2-linux-i586-rpm

#cd?/usr/java/

#ln?-s?j2sdk1.4.2/?jdk/

To set environment variables:

Don't write about it in the/etc/profile. That would cause the JDK to be available for each user to start.

Because you want to use Tomcat, write to Tomcat's home directory.

#vi/HOME/TOMCAT/.BASHRC (or Bash_profile)

Export? Java_home=/usr/java/jdk

Export? Path= $PATH: $JAVA _home/bin

Export? Classpath= $JAVA _home/lib

Su to Tomcat users to see if they can use

#su?-? Tomcat

$javac

$java

Do you have a show? If so, the JDK configuration is successful.

Re-su to root

2. Configure Tomcat

Tomcat I was started by tomcat this user, please note:

Because I downloaded the binary version, I do not need to compile again.

#cp?/download/jakarta-tomcat-4.1.30.tar.gz?/usr/local

#tar? zxvf?jakarta-tomcat-4.1.30.tar.gz

#rm?-f?jakarta-tomcat-4.1.30.tar.gz

#cd? jakarta-tomcat-4.1.30

To add an environment variable:

#vi?/HOME/TOMCAT/.BASHRC

Export? Catalina_home=/usr/local/tomcat

Export? Catalina_base=/usr/local/tomat

You can test whether Tomcat starts properly:

#bin/startup.sh

You'll see the stuff:

Using? Catalina_base:??? /usr/local/tomcat

Using? Catalina_home:??? /usr/local/tomcat

Using? Catalina_tmpdir:?/usr/local/tomcat/temp

Using? Java_home:??????? /usr/java/jdk

Then open the browser, enter http://localhost:8080, if you can see a sick kitten looking at you, then congratulations, Tomcat also became.

3. Install PostgreSQL

Now that you have downloaded the PostgreSQL installation package, and it is rpm, installation is very convenient: to http://www.postgresql.org to go down of course, there are many mirror, I went to Taiwan's a mirror site under the FOR?AS3 package, You can also look for it, download to the/download directory

#cd?/download

#rpm-IVH?--nodeps?postgresql*.rpm????????? Be sure to add--nodeps, rest assured that the use of installed after no problem

When you are done, you can use the #service?postgresql?start????? To start Pgsql, if you see Starting?postgresql?service:?????????????????? [? OK?] So, Pgsql can also run, of course, you can look at the default settings:

#su?-? Postgres

#psql

Of course, remember to Initdb first.

Now, let's start testing servlet,jsp, and JSP connections PostgreSQL

4.Tomcat Test

First of all, we test the JSP, because this is relatively simple.

#cd?/usr/local/tomcat/webapps

#mkdir????????????????????-p?myapp/web-inf? Note case

#cp? Root/web-inf/web.xml?myapp/web-inf

#vi? myapp/index.jsp

This is not accessible through http://localhost:8080/myapp/index.jsp, and you need to add a context to Tomcat

VI?.. /conf/server.xml

Find and then add the paragraph after it.

Restart Tomcat and enter http://localhost:8080/myapp/index.jsp in the browser

If it's normal, then congratulations, it worked.

Second, test the servlet

Write one of the simplest servlet first.

package?test;?
import?java.io.*;
import?javax.servlet.*;
import?javax.servlet.http.*;
Public?class? Test?extends? HttpServlet? {?
Protected?void?doget (Httpservletrequest?request, huh?) Httpservletresponse?response)?
Throws? Servletexception, huh? IOException? {?
Printwriter?out=response.getwriter ();?
Out.println ("
This?is?a?servlet?test.
");??
}?
}



Save the above file as Test.java, then compile with Javac, copy the resulting Test.class file to/usr/local/tomcat/webapps/myapp/web-inf/classes/test/

Modify the Myapp/web-inf/web.xml, the change is probably like this

?
Public? " -//sun? Microsystems,?inc.//dtd? Web? application?2.3//en "?
"Http://java.sun.com/dtd/web-app_2_3.dtd"?
?
?
A?application?for?test.?
?
?
Test?
Test. Test?
?
?
Test?
/test?
?



Restart TOMCAT4, open the browser input http://localhost:8080/myapp/Test, should be displayed this?is?a?servlet?test.

If there is an error, 400 error, said not found the file, should be Server.xml did not write the context, if it is 500 error, then the program has a problem:

Please resolve other errors yourself.

5. Connecting to the database

This need PostgreSQL jdbc, we started rpm?-ivh?post*.rpm, already installed, use rpm?-qa?|? Grep?post

Find out the name of the package for this JDBC

Ostgresql-7.4.1-1pgdg

Postgresql-jdbc-7.4.1-1pgdg

Postgresql-libs-7.4.1-1pgdg

Find the path to it.

#rpm?-ql?postgresql-jdbc-7.4.1-1pgdg

Found in/usr/share/pgsql/, the list of files is as follows:

/usr/share/pgsql/pg74.1jdbc1.jar

/usr/share/pgsql/pg74.1jdbc2.jar

/usr/share/pgsql/pg74.1jdbc2ee.jar

/usr/share/pgsql/pg74.1jdbc3.jar

This jdbcx.jar corresponds to the JDBC version respectively, and I made jdbc2.0, so I did

#cp? pg74.1jdbc2.jar?pg74.1jdbc2.jar.bak

#mv? Pg74.1jdbc2.jar?postgresql.jar

Put the Postgresql.jar in the/usr/java/jdk/jre/lib/ext/, or you can add it to the classpath.

Write a simple JSP script to test the connection database

pgsql.jsp
?
?
?
?
?
Your first field content is:?
The contents of your second field are:?
?
?
?
?
?

Save this file under myapp/and then http://localhost:8080/myapp/pgsql.jsp, there should be no problem, I have tested it through.

Congratulations, a simple development environment has been built

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.