eclipse java web configuration

----------------------------------------??? Java_ee_sdk-5_07-jdk-6u16 -windows.exe + tomcat 6 / 5u7-6u16-ml/java_ee_sdk-5_07-jdk-6u16-windows.exe? AuthParam = 1257127940_90bf6ab30b793fdc95a0a8b75ec3881b & TicketId = nod3BVAYR3B9lOAglUOUU5% 2BddA% 3D% 3D & GroupName = CDS & FilePath = / ESD6/JSCDL/java_ee_sdk/5u7-6u16-ml/java_ee_sdk-5_07-jdk-6u16-windows.exe & File = java_ee_sdk-5_07-jdk-6u16-windows.exe

----------------------------------- J2SDK [jdk-6u13-windows-i586-p] and TOMCAT5. 5 of the installation and configuration [attached apache-tomcat5 Download]

Step One: Download j2sdk 【jdk-6u13-windows-i586-p.exe】 and tomcat: to the sun official site oprogramowanie/java/stare/jdk-6u13-windows-i586-p.exe

【Latest jdk 1.5 jdk-6u13-windows-i586-p.exe】, tomcat 5.5, jdk1.4 or above recommended, tomcat4.0 above the second step: to install and configure your j2sdk and tomcat: implementation of the j2sdk and tomcat installation program, and then set in accordance with the path can be installed.
1. Install j2sdk later, need to configure the environment variables look in My Computer -> Properties -> Advanced -> Environment Variables -> System Variables, add the following environment variables (assuming your j2sdk installed in c: \ j2sdk1.4.2):
JAVA_HOME = c: \ j2sdk1.4.2
classpath =.;% JAVA_HOME% \ lib \ dt.jar;% JAVA_HOME% \ lib \ tools.jar; (.; must not be less, because it represents the current path)
path =% JAVA_HOME% \ bin

Then you can write a simple java program to test J2SDK is installed successfully:
public class Test (
public static void main (String args []) (
System.out.println ("This is a test program.");
The above procedure will save this file as a file named
Then open a command prompt window, cd to the directory where your, and then type the following command
java Test
At this point, if you see printed This is a test program. Then you're done, if not print out this sentence, you need to carefully check your configuration.

2. After installing Tomcat, in My Computer -> Properties -> Advanced -> Environment Variables -> System Variables, add the following environment variables (assuming your tomcat installed in c: \ tomcat):
CATALINA_HOME: c: \ tomcat
CATALINA_BASE: c: \ tomcat
TOMCAT_HOME: C: \ Tomcat
And then modify the environment variable in the classpath, the tomat installation directory common \ lib under the servlet.jar to the classpath in additional to, the modified classpath is as follows:
classpath =.;% JAVA_HOME% \ lib \ dt.jar;% JAVA_HOME% \ lib \ tools.jar;% CATALINA_HOME% \ common \ lib \ servlet.jar;
Then you can start tomcat, in IE to access http://localhost:8080 , if the tomcat welcome page to see if install succeeded.
Third step: create your own jsp app directory
1. To the Tomcat installation directory of the webapps directory, you can see ROOT, examples, tomcat-docs like Tomcat that comes with the catalog;
2. In the webapps directory, create a directory named myapp;
3.myapp create a directory under WEB-INF, note the directory name is case-sensitive;
4.WEB-INF create a file under the web.xml, as follows:
<? Xml version = "1.0" encoding = "ISO-8859-1"?>

<! DOCTYPE web-app
PUBLIC "- / / Sun Microsystems, Inc. / / DTD Web Application 2.3 / / EN"
" ">

<display-name> My Web Application </ display-name>
A application for test.
</ Description>
</ Web-app>
5. Myapp a test under the new jsp page, the file named index.jsp, file reads as follows:
<html> <body> <center>
Now time is: <% = new java.util.Date ()%>
</ Center> </ body> </ html>
6. Restart Tomcat
7. Open your browser, enter the http://localhost:8080/myapp/index.jsp see the current time, then shows a success.
Step Four: Create your own Servlet:
Write your first Servlet
import *;
import javax.servlet .*;
import javax.servlet.http .*;
public class HelloWorld extends HttpServlet
public void doGet (HttpServletRequest request, HttpServletResponse response) th
rows ServletException, IOException
response.setContentType ("text / html");
PrintWriter out = response.getWriter ();
out.println ("<html> <head> <title>");
out.println ("This is my first Servlet");
out.println ("</ title> </ head> <body>");
out.println ("<h1> Hello, World! </ h1>");
out.println ("</ body> </ html>");

Then still use the javac to compile this file, if there is no import javax.servlet .*
So that should be C: \ Tomcat \ common \ lib inside the servlet.jar file copied to the C: \ JDK \ jre \ lib \ e
xt, the re-compiled, no problem!
Then in the Tomcat directory inside the C: \ Tomcat \ webapps \ ROOT inside the file structure as follows:
ROOT \ index.html
ROOT \ welcom.jsp
ROOT \ WEB-INF \ lib \ MyServlet.jar (If your servlet's. Class to play has become. Jar file, then on the lib below)
ROOT \ WEB-INF \ classes \ HelloWorld.class (to top generate HelloWorld.class file on the inside)
Then enter in your browser http://localhost:8080/servlet/HelloWorld , then Server welcomed by the error of: Error 404 - Not Found
How going on?
Servlet must use the C: \ Tomcat \ webapps \ ROOT \ WEB-INF web.xml file in this directory the following register
Open the web.xml file with the EP,

To following this procedure
<! - [If! SupportLineBreakNewLine] ->
<! - [Endif] ->


<servlet-name> org.apache.jsp.index_jsp </ servlet-name>

<servlet-class> org.apache.jsp.index_jsp </ servlet-class>

</ Servlet>


<servlet-name> org.apache.jsp.index_jsp </ servlet-name>

<url-pattern> / index.jsp </ url-pattern>

</ Servlet-mapping>
<servlet-name> HelloWorld </ servlet-name>
<servlet-class> HelloWorld </ servlet-class>
</ Servlet>
<servlet-name> HelloWorld </ servlet-name>
<url-pattern> / servlet / HelloWorld </ url-pattern>
</ Servlet-mapping>
If not, add that code directly

Because such a structure
<servlet-name> HelloWorld </ servlet-name>
<servlet-class> HelloWorld </ servlet-class>
</ Servlet>
That contains the servlet class specified.
The following structure
<servlet-name> HelloWorld </ servlet-name>
<url-pattern> / servlet / HelloWorld </ url-pattern>
</ Servlet-mapping>
That should be mapped out what it designated HelloServlet URL pattern.
After completion of the modified web.xml, restart the Server, and then re-enter http://localhost:8080/servlet/HelloWorld , so huge a Hello, World! etc.


------------------------------------ 1 eclipse the various download versions

eclipse-java java development general use. 92M-free pure java development web development, then recommend the first one, plug-less, the speed and resource consumption will be less.
eclipse-jee JavaEE direction can use this version. 189M for web development without taking into account the speed and memory, there is no difference between the first two.
eclipse-modeling plug-in development and modeling.
eclipse-rcp RCP development.
eclipse-reporting this is not clear to see the name of estimates made statements. 219M
Eclipse-SDK [ Eclipse Classic ] this is equivalent to the standard version, can do a general plug-in development, and java development. 162M-free web development

------------------------------------ 2 eclipse configuration

1 Configure JREs

Open the configuration dialog
preferences - java-installed jres
In the pop-up dialog box to select your installed JDK6

standard VM
C: \ jdk1.6.0_13

After clicking OK you can repeat the above action, add JRE6

2 Configure Tomcat

preferences --- server-installed runtime enironment - add

In the following dialog box that opens, select Tomcat 5.5

Choose your address bar in the Tomcat Tomcat installation directory, in the JRE column selection JDK1.6.0, Tomcat startup time in the future, if prompted

JRE configuration errors, can be modified to be back here. Click Finish.

New java web project:

File - New-OTHER-web-dynamic web project

3 Import Export

file-import: general-existing projects into workspace

General can import folders and zip archive, etc.

Export war:

To turn off tomcat,

Right Projects> Export - war file, and then the war Export pop-up dialog box, select the Destination directory for the webapp, and then click the Finish button.
Open the tomcat, in ie you can access the changed item, **. war will automatically extract into a directory for the tomcat access

4 Show Line Numbers

Window> Preferences ... to open the Preferences Settings dialog box, almost all of Eclipse's settings options can be found here. To display line numbers, you can expand the node General> Editors> Text Editors, Show Line Numbers

5, source code formatting

Sometimes confused handwritten code, this time can first select to format code (do not choose to format the current document is all the code), by selecting the menu Source> Format or right-click in the editor, select menu Source> Format

6 getter and setter methods generated

Often when writing to write a JavaBean template of the getXXX () and setXXX () this way, we can use Eclipse to automatically generate the template-based approach. First written private String name;, then select the Source> Generate Getters and Setters ... or right-click in the editor, select menu Source> Generate Getters and Setters ... you can open the Generate Getters andSetters dialog box, in the dialog box, select Build method, and then click OK button.

7 automatically generated constructor

Recommended first define the variables, source generate constructor with fields

8 Notes and uncomment

Ctrl + /

9 eclipse custom library:
windows - java - Build path - user Libraries --- new: user library name to hibernate, do not check the system library; select hibernate, "Add JARs", into Hibernate, JDBC package, OK

A custom library for the project:
Right project - properties - java build path - libraries - add library - user library, select the database we can build the hibernate

------------------------------------ 3 eclipse error

1 problem occurred

unhandled event loop exception

permgen space

PermGen space full name is the Permanent Generation space, refers to the memory of the permanent preservation areas OutOfMemoryError: PermGen space memory benefits from the surface is out, the solution also must increase the memory.

Solution eclipse.ini:

-Vmargs: Description of parameters followed by the VM
-Xms128m: Virtual Machine occupy the minimum system memory
-Xmx512m: virtual machine system, the maximum memory occupied 5% of 25.6M, the theory goes-Xmx value with the-XX: MaxPermSize
Must be greater than 25.6M
-XX: PermSize: minimum heap size. General reported that memory is low, are saying that this is too small
Heap space will be less than 5% remaining warning, proposed to set up a little
Great point, but depending on your machine to set the memory size
-XX: MaxPermSize: maximum heap size. This also has more appropriate

To change the parameters inside
-XX: PermSize = 128M
-XX: MaxPermSize = 256M

2 java.lang.OutOfMemoryError: Java heap space

----------------------------------------------- 4 mysql- connector-java [attached download]

Download the jar to connect mysql package, such as: mysql-connector-java-5.0.4-bin.jar, the jar package to your project.
The following is a link code

Build java files
import java.sql.DriverManager;
public class test (

/ **
* @ Param args
* /
public static void main (String [] args) (
/ / TODO Auto-generated method stub
Class.forName ("com.mysql.jdbc.Driver");
System.out.println ("Success loading MySQL Driver ...");
catch (Exception ex)
System.out.println ("Error loading MySQL Driver ...");
ex.printStackTrace ();
try (
Object conn = DriverManager.getConnection ("jdbc: mysql: / / localhost: 3306/zfblog? User = root & password = 123456");
System.out.println ("Success connect Mysql Database!");
catch (Exception e)
e.printStackTrace ();


1 Right-project-properties for --- java build path --- libraries: add txternal jars
2 If your project is a tomcat project, the mysql-connector-java-3.1.13-bin.jar in this package, this package into the WEB-INF \ lib and then right the jar under the package -> build path-> add to build path manually to the jar package to your project
3 or the jar package into the tomcat installation directory \ common \ lib Next, put it here, all the eclipse of the project can share this jar package

----------------------------------------------- 5 xml configuration explain

<! - Specify the index page ->
<welcome-file> index.jsp </ welcome-file>
<welcome-file> index.html </ welcome-file>
</ Welcome-file-list>

<! - The specified error page ->
<error-code> 404 </ error-code>
<location> / NotFound.jsp </ location>
</ Error-page>
<exception-type> exception.ServletNotFound </ exception-type>
<location> / sorry.jsp </ location>
</ Error-page>

<description> </ description>
<display-name> AdminLoginServle </ display-name>
<servlet-name> AdminLoginServle </ servlet-name>
<servlet-class> </ servlet-class> --- servlet-class
</ Servlet>
<servlet-mapping> - URL pattern in the Servlet and define a mapping between
<servlet-name> AdminLoginServle </ servlet-name> --- <servlet-name> Servlet given element name must be declared in the <servlet> element in the Servlet name
<url-pattern> / admin / AdminLoginServle </ url-pattern> ----< url-pattern> element specifies the URL corresponding to Servlet path, the path is relative to the Web application context path root
</ Servlet-mapping>

----------------------------------------------- 6 modify tomcat Main Menu

Open the C: \ Tomcat \ conf \ server.Xml, in <host> </ host> adding between Code: China Network Management Alliance
<Context Path="" docBase="E:\workspace_eclipse_java" debug="0" reloadable="true" crossContext="true"/>
This restart tomcat

分类:Java 时间:2010-04-02 人气:469
blog comments powered by Disqus


  • java中File类的使用方法 2014-06-05

    本篇文章介绍了,在java中File类的使用方法.需要的朋友参考下 构造函数 public class FileDemo { public static void main(String[] args){ //构造函数File(String pathname) File f1 =new File("c:\\abc\\1.txt"); //File(String parent,String child) File f2 =new File("c:\\abc",&quo

  • The way the XML file Jdom. Document.String conversion between 2011-05-03

    XML file: <?xml version="1.0" encoding="UTF-8"?><books><book><name> Harry Potter </name><price>10</price><memo> This is a very good book .</memo></book></books> Java cod

  • java data type conversion Integer String Long Float Double Date 2010-07-24

    1 How to convert integer string String int? A. There are two ways: 1). Int i = Integer.parseInt ([String]); or i = Integer.parseInt ([String], [int radix]); 2). Int i = Integer.valueOf (my_str). IntValue (); Note: The string converted to Double, Floa

  • Java, how to convert a string into a date format 2010-10-05

    Java, convert string into date format is commonly used as a function of Among many projects, will use the drops, is also useful prior to, but I am a bad memory So, decided to write this blog, frequently used functions to facilitate the later can be u

  • Java to determine whether the string contains characters 2010-11-19

    Java to determine whether the string contains characters import java.util.regex.Matcher; import java.util.regex.Pattern; public class IfHanZi { public static void main(String[] args) { // Method a : String s1 = " I am a Chinese "; String s2 = &q

  • Java String object, the classic problem of (new String ()) [switch] 2011-08-05

    Look at an example, the code is as follows: Java code public class Test { public static void main (String [] args) { String str = "abc"; String str1 = "abc"; String str2 = new String ("abc"); System.out.println (str == str1);

  • Practical Guide for Java programmers Bash series of string processing (directory) 2011-08-31

    Practical Guide for Java programmers Bash series of string processing (directory) In general computer programming language, string handling is very important one, Bash, too, if the master of the string processing, basically to be able to meet most of

  • Java进阶教程之String类 2013-10-16

    这篇文章主要介绍了Java进阶教程之String类,String类对象是不可变对象(immutable object),String类是唯一一个不需要new关键字来创建对象的类,需要的朋友可以参考下 之前的Java基础系列中讨论了Java最核心的概念,特别是面向对象的基础.在Java进阶中,我将对Java基础进行补充,并转向应用层面. 大部分编程语言都能够处理字符串(String).字符串是有序的字符集合,比如"Hello World!".在Java中,字符串被存储为String类对象

  • Java stack and the heap String Xiangjie 2010-04-13

    Java stack and the heap 1. Stack (stack) and heap (heap) are Java is used to store the data in the Ram in place. With the C + + different, Java programmers automatically manage the stack and heap can not be directly set the stack or heap. 2. Stack ad

  • JAVA in the difference between String and StringBuffer 2010-01-18

    In java there are three character classes to be responsible for the operation. 1.Character carrying out a single character to operate, 2.String right to operate a string of characters. Immutable class. 3.StringBuffer also to operate a string of chara

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.838 (s). 12 q(s)