Servlet/jsp configuration entry

Source: Internet
Author: User

First, download the tool:
We recommend that you use editplus + JDK for beginners. I think it is convenient to use editplus + JDK, such as JB, eclipse, and jcreator, but it does not know how to configure environment variables for beginners,
Thus it is difficult to reach the point of knowing and knowing why.
You can download it at the following address:
Editplus (the latest version is v2.11): http://count.skycn.com/softdown.php? Id = 3641 & url = http://sc-http.skycn.net/down/epp211a_cn.exe (you need to follow the registration code to find it yourself, a lot of online)
JDK (the latest version is java2sdk3164_2): http://count.skycn.com/softdown.php? Id = 3116 & url = http://sc-http.skycn.net/down/j2sdk-1_4_2-windows-i586.exe (this is for Windows)

Then install JDK. I installed it under the C:/JDK directory:
Then there is the classpath problem:
Just as the operating system uses path to search for executable programs, the Java Runtime Environment will traverse classpath to find classes. Even a simple program such as helloworld will traverse the JVM.
Classpath defines every path until the corresponding file is found.
I believe that if your system is not 2 K or XP, you should set the path as follows:
My computer-> properties-> advanced-> Environment Variables
Append the following path to the environment variable: C:/JDK/bin;.; C:/JDK/lib.
You can also configure C:/JDK/bin;.; C:/JDK/lib/dt. jar; C:/JDK/lib/tools. jar.
★Remember: In the environment variables, remember not to be less. It indicates the current path. If there are fewer errors, you will say it!
DT. jar is a class library about the runtime environment, and tools. jar is a class library about some tools.
If C:/JDK/bin is not configured, "javac" is not an internal or external command, or a program or batch file that can be run ." This error occurs.
Then we should write the program:
The first is (helloworld. Java). Open editplus and create a new Java file. Enter the following information to keep it case-insensitive:
Public class helloworld {
Public static void main (string [] ARGs ){
System. Out. println ("Hello, world! ");
}
}
Then save the file (CTRL + S) to helloworld. java. Remember to distinguish the case sensitivity. helloworld. Java is not helloworld. Java or other
Run the following command: Start-> Run-> cmd
Switch the directory to the current directory in the console:
Javac helloworld. Java
Java helloworld
You will see the output Hello, world on the console! (Not coming out? I have eaten my computer :))
Javac is a compilation command that compiles helloworld. Java into helloworld. Class.
Java is the command to explain. JVM will explain and execute helloworld. Class.
At this time:
1. If exception occurs in thread "Main" Java. Lang. noclassdeffounderror: helloworld
That is, you didn't add that. (DOT) to the environment variable)
2. If exception in thread "Main" Java. Lang. nosuchmethoderror: Main appears
Or helloworld. Java: 1: Public class helloworld must be defined in a file called

"Helloworld. Java ".
That is, you did not write this helloworld case-insensitive, or you did not save it as helloworld. Java
This name must be the same as the public class name.

Let's talk about the problem of environment variables. Next, let's talk about how to compile and run the environment variables in editplus, and choose tools> parameter settings> Configure user tools.
1. Add a tool (add an Application)
Menu text: compile Java program
Program: C:/JDK/bin/javac.exe
Parameter: File Name
Initial Directory: file directory
2. Add a tool (add an Application)
Menu text: run Java program
Program: C:/JDK/bin/java.exe
Parameter: File Name (excluding the extension)
Initial Directory: file directory

You can add a tool group name as needed, such as debug Java program.
Then, in the drop-down menu of tools, you will see the compile Java program and run Java program options. Then you can use Ctrl + 1 to compile and CTRL + 2 to run the program.

The following describes how to run servlet:
To run servlet, JSP/servlet iner is required. We recommend that you use Tomcat for beginners.
Tomcat (Latest Version 5.0): http://cvs.apache.org/builds/jakarta-tomcat-5/nightly/jakarta-tomcat-5-bin-20030725.zip
Decompress the package:
C:/tomcat
Then configure the environment variable:
Add three system variables:
Java_home: C:/JDK
Tomcat_home: C:/tomcat
Classpath: % java_home %/LIB; % tomcat_home %/lib
The environment variables of Tomcat are configured. Check whether Tomcat can run as follows:
In the console, go to the C:/tomcat/bin directory and run startup. Then, a window appears, which means that the server has been running.
Enter http: // localhost: 8080 in the browser. If the welcome page appears, it means Tomcat is okay.
Write your first Servlet as above.
Import java. Io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class helloworld extends httpservlet
{
Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception
{

Response. setcontenttype ("text/html ");
Printwriter out = response. getwriter ();
Out. println ("");
Out. println ("

Hello, world!

");
Out. println ("");

}
}
Then use javac helloworld. Java to compile the file. If the file cannot be imported javax. servlet .*
Then, copy the servlet. jar file in C:/tomcat/common/lib to C:/JDK/JRE/lib/EXT and compile it again!
Then, in the Tomcat directory c:/tomcat/webapps/root, follow the following file structure:
Root/index.html
Root/Welcom. jsp
Root/WEB-INF/lib/myservlet. Jar (If your servlet. Class is typed into a. jar file, put it under Lib)
Root/WEB-INF/classes/helloworld. Class (put the above generated helloworld. Class file in this)

Then, enter http: // localhost: 8080/servlet/helloworld in the browser. The Error 404 -- not found is returned by the server.
What's going on?
Servlet must use the C:/tomcat/webapps/root/WEB-INF directory under the Web. xml file registration, open this web. xml file with EP,
Add

Helloworld
Helloworld


Helloworld
/Servlet/helloworld

Such a structure

Helloworld
Helloworld

Indicates the specified servlet class.
The following structure

Helloworld
/Servlet/helloworld

Specifies the URL mode to which helloservlet maps.
After modifying web. XML, restart the server and then enter http: // localhost: 8080/servlet/helloworld. Then, a large Hello, world! Waiting for you. Congratulations.
Flat :)
AI, the hands are tired. Write it here. I hope it will be helpful for beginners!

========================================================== ==========================================
How to Create a database connection application? For example, connecting access and SQL Sever.
I have heard that there are JDBC-ODBC bridges and other methods. Currently, my machine only has jdk1.4. Do I need to install any other environment in JDBC mode?
If you want a JDBC driver or other environment, where can I go? How can programs be written?
---------------------------------------------------------------
 
If the drive axle is used, you do not need to install anything else.
In
Control Panel --> Administrative Tools --> data source (ODBC) --> systemdsn
Add your database ing and select the corresponding database driver.
Then you can use
JDBC: ODBC: the configured DSN name
To connect to the database.
---------------------------------------------------------------
 
Package cbk00d. Common;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @ Author
* @ Version 1.0
*/
Import java. Io .*;
Import java. util .*;
Import java. SQL .*;
Import java. Lang .*;
Public class dbconnect {
Private string jdbcdriver = NULL;
Private string jdbcurl = NULL;
Private string username = NULL;
Private string Password = NULL;
Public dbconnect (){
Jdbcdriver = "Sun. JDBC. ODBC. jdbcodbcdriver ";
Jdbcurl = "JDBC: ODBC: CBK ";
Username = "system ";
Password = "manager ";
}
Public connection getconnection (){
Connection connection = NULL;
Try {
Class. forname (jdbcdriver );
Connection = drivermanager. getconnection (jdbcurl, username, password );
} Catch (exception e ){
System. Out. println (E );
}
Return connection;
}
}
This is a common connection method! You just need to modify it.
---------------------------------------------------------------
 
It seems like this. Rs. Next () is required first.
Is the JDBC-ODBC bridge not good? Pai_^

Java can connect to a database in multiple ways:
There are four types of database drivers:
1:1 class driver. This is the way JDBC-ODBC bridges are built. However, this method is not suitable for program reuse and maintenance and is not recommended. The ODBC driver of the database is required.
2: Class 2 driver. This is the form of JDBC + vendor API. Vendor APIs are generally written in C. Therefore, this method is not long-lived.
Class 3 drivers. This is the form of JDBC + vendor database connection SERVER + database.
In this way, a server dedicated to database connection is provided between Java and database (generally provided by database vendors ). The advantage is that the connection can be optimized.
Class 4 driver. This is the connection method of pure JDBC + database. It is also recommended connection method. This separates applications from databases. Developers only need to focus on the implementation of internal logic, rather than the specific implementation of database connections. There are two Connection Methods:
The hard encoding method is required for hard-coded database connection in a program.
JNDI datasource mode. It is to set a datasource data source in the external environment of the program running, also known as (context), with a JNDI name. The program only needs to find this name to get a database connection object.

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.