Java Development Manual (fragmented)

Source: Internet
Author: User

Tomcat-5.5 \ conf \ server. xml port configuration TOMCAT needs to be restarted

The installation path of MyEclipse 7.0 of different versions is different, and the folder content structure is different. As a result, how can I compile the tomcat plug-in 8.5?

C: \ Program Files \ Genuitec \ MyEclipse 8.5
C: \ Program Files \ Genuitec \ Common

C: \ Program Files \ Genuitec \ Pulse Explorer \ plugins
C: \ Documents ents and Settings \ Administrator \ workspace

C: \ Program Files \ MyEclipse 7.0M1

The webapps website and directory under the tomcat directory are similar to the IIS root directory.

The following is an excerpt from Baidu know for reference only.

Step 1: Download jdk and tomcat

Step 2: install and configure your jdk and tomcat: Execute the jdk and tomcat installation programs, and then set the installation according to the path.

1. after installing j2sdk, You need to configure the environment variables, add the following environment variables to my computer> Properties> advanced> environment variables> system variables (assuming your jdk is installed in c: \ jdk1.6 ):

JAVA_HOME = c: \ jdk1.6

Classpath =.; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib \ tools. jar; (.; must not be small, because it represents the current path)

Path = % JAVA_HOME % \ bin

Then, you can write a simple java program to test whether JDK has been installed successfully:

Public class Test {

Public static void main (String args []) {

System. out. println ("This is a test program .");

}

}

Save the above program as a file named Test. java.

Then open the Command Prompt window, cd to the directory where your Test. java is located, and then type the following command

Javac Test. java

Java Test

If This is a test program is printed, the installation is successful. If This is not printed, You need to carefully check your configuration.

 

2. after Tomcat is installed, add the following environment variables to my computer> Properties> advanced> environment variables> system variables (assuming your tomcat is installed in c: \ Tomcat ):

CATALINA_HOME: C: \ Tomcat

CATALINA_BASE: C: \ Tomcat

TOMCAT_HOME: C: \ Tomcat

Modify the classpath in the environment variable and append the servlet. jar under the common \ lib under the tomat installation directory to the classpath. The modified classpath is as follows:

Classpath =.; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib \ tools. jar; % CATALINA_HOME % \ common \ lib \ servlet. jar;

Start tomcat and access http: // localhost: 8080 in IE. If you see the welcome page of tomcat, the installation is successful.

Step 3: Create your own jsp app directory

1. Go to the webapps directory of the Tomcat installation directory, and you can see the tomcat built-in directories such as ROOT, examples, and Tomcat-docs;

2. Create a directory named myapp under the webapps directory;

3. Create a directory WEB-INF under myapp, note that the directory name is case sensitive;

4. Create a file web. xml under the WEB-INF with the following content:

<? Xml version = "1.0" encoding = "ISO-8859-1"?>

<! DOCTYPE web-app

PUBLIC "-// Sun Microsystems, Inc. // DTD Web Application 2.3 // EN"

Http://java.sun.com/dtd/web-app_2_3.dtd>

<Web-app>

<Display-name> My Web Application </display-name>

<Description>

A application for test.

</Description>

</Web-app>

5. Create a test jsp page under myapp. The file name is index. jsp. The file content is as follows:

<Html> <body> <center>

Now time is: <% = new java. util. Date () %>

</Center> </body>

6. Restart Tomcat

7. Open the browser and enter http: // localhost: 8080/myapp/index. jsp to view the current time.

Step 4: Create your own Servlet:

Write your first Servlet

Import java. io .*;

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 ("

Out. println ("This is my first Servlet ");

Out. println ("</title>

Out. println ("

Out. println ("</body> }

}

Then use javac HelloWorld. java to compile the file.

Et .*

Then, copy the servlet. jar file in C: \ Tomcat \ common \ lib to C: JDKjrelibe.

In xt, compile again, and there will be no problem!

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 the. jar file, put

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 be registered using the web. xml file under the directory C: \ Tomcat \ webapps \ ROOT \ WEB-INF,

Open the web. xml file with EP,

Set the following procedure

Servlet>

.....

</Servlet>

<Servlet-mapping>

......

</Servlet-mapping>

Replace

<Servlet>

<Servlet-name> HelloWorld </servlet-name>

<Servlet-class> HelloWorld </servlet-class>

</Servlet>

<Servlet-mapping>

<Servlet-name> HelloWorld </servlet-name>

<Url-pattern>/servlet/HelloWorld </url-pattern>

</Servlet-mapping>

If not, add the Code directly.

Why?

Because of this structure

<Servlet>

<Servlet-name> HelloWorld </servlet-name>

<Servlet-class> HelloWorld </servlet-class>

</Servlet>

Indicates the specified servlet class.

The following structure

<Servlet-mapping>

<Servlet-name> HelloWorld </servlet-name>

<Url-pattern>/servlet/HelloWorld </url-pattern>

</Servlet-mapping>

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! And so on

Congratulations!

Flat :)

Add the following statement at the beginning of the JSP file to display the Chinese name

<% @ Page language = "java" contentType = "text/html; charset = gb2312" %>

Modify conf \ server. xml in the tomcat directory

Port = "8080" maxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"

EnableLookups = "false" redirectPort = "8443" acceptCount = "100"

Debug = "0" connectionTimeout = "20000"

DisableUploadTimeout = "true" URIEncoding = "UTF-8"/>

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.