Java Tomcat website deployment first day
Install Apache Tomcat 5.0, default has Tomcat service running, joining JSP files in the root directory, does not work. Use the command window to run. Run "E: / Program Files / Apache Software Foundation / Tomcat 5.0 / Bin / Startup.bat",
Environment variable configuration:
Tomcat's root directory Catalina_Home:
E: / Program Files / Apache Software Foundation / Tomcat 5.0
Java's class path [first point ".;" Represents the current path] ClassPath:
.; C: /J2SDK1.4.2_04; C: /J2SDK1.4.2_04/lib/tools.jar; C: /J2SDK1.4.2_04/lib/dt.jar; C: / J2SDK1. 4.2_04 / lib / Tools.jar; C: /J2SDK1.4.2_04/lib/htmlconverter.jar; C: /J2SDK1.4.2_04/lib/servlet.jar; M: / Java
Java root directory java_home:
C: /j2sdk1.4.2_04
Add C: /J2SDK1.4.2_04/bin in the PATH environment variable; then run JavaC.exe directly, Java.exe can find the executable file corresponding to Java.
For WinXP, the system environment variable does not need to restart the system, but it is necessary to reopen the application, and the user variable needs to restart the system to take effect.
EDIT PLUS Java Environment Configuration:
It turned out that JCREATOR was used to write Java code, and it was a configuration written by J2ME Motorola's mobile phone program, which is much more complicated. You can refer to:
Write a mobile phone program Please use jcreator pro sunyuzhe114 [original]
http://dev.9cbs.net/develop/Article/13/13625.shtm
Here Edit Plus is mainly to add commands in Tools / Configure User Tools .... The simple configuration here is as follows:
Group name ...: Java Tools
Function: Compiling Java files to generate Class to Java files where
Menu Text: Java Compile
Command: c: /j2sdk1.4.2_04/bin/javac.exe
Argument: $ (filename)
Initial Directory: $ (filedir)
Function: Run the generated class file
Menu Text: Java Run
Command: c: /j2sdk1.4.2_04/bin/java.exe
Argument: $ (Filenamenoext)
Initial Directory: $ (filedir)
Function: [Open Class File] Directly in Directly with JAD, generate Java files to the Class file
Menu Text: Jad Decompile
Command: m: /java/tools/jad_win/jad.exe
Argument: -o -d ./ -s java $ (filenamenoext) .class
Initial Directory: $ (fileDir)
Function: Open the anti-compilation generated Java file with Edit Plus
Menu Text: Open Decompile File
Command: E: / Program Files / EditPlus 2 / Editplus.exe
Argument: $ (filenamenoext) .java
Initial Directory: $ (fileDir)
After adding custom tools, use Ctrl 1 [~ N] to run custom tools.
/ * The [root directory] below
* E: / Program Files / Apache Software Foundation / Tomcat 5.0 / WebApps / Root
* /
Java Bean deployment process:
1. [Root Catalog] / Web-INF / CLASS / TEST / New FAQ.TXT, renamed FAQ.JAVA
2. FAQ.java Enter the content:
Package test;
PUBLIC CLASS FAQ {
Public FAQ () {
System.out.Println ("FAQ Construction Method");
}
Public Sayhello () {
System.out.println ("FAQ: Hello World!");
}
}
3. Compile the above, in [root directory] / web-inf / class / test / generation * .class file.
4. [Root Catalog] / TEST / New FAQ.txt, renamed FAQ.JSP
5. FAQ.JSP input content:
<%
Workm.SAYHELLO ();
%>
6. Phenomenon: Sayhello outputs "FAQ: Hello World!" In Tomcat; uses System.out.Println in the JSP file. Out.println outputs directly to the browser.
7. Method of Usage of Java Bean: Add a reference to JSP
<% @ Page Import = "Test. *"%>
When called,
FAQ Myfaq = New FAQ ();
Myfaq.sayhello ();
The advantage of this method is that the object can be defined multiple times in each JSP.
Servlet deployment process:
1. In [root directory] / web-inf / class / test / new FAQServlet.txt, renamed FAQSERVLET.JAVA
2. FAQSERVLET.JAVA Enter content:
Package test;
Import java.io. *;
Import javax.servlet.http. *;
Import javax.servlet. *;
Public Class FAQSERVLET EXTENDS HTTPSERVLET
{
Public void doget (httpservletRequest Request, httpservletResponse response) throws oException, servletexception {
Response.setContentType (Text / XML ");
PrintWriter out = response.getwriter ();
Out.println ("
Hello World!
");
}
}
Servlet is a collective name from all objects derived from httpservlet. Mainly handle DOGET, DOPOST two methods, doget is a general situation, the browser takes a web page from the server, Dopost is the browser to take data from the server via the POST, such as the form of Form's Method = "post" submitted to the server.
3. [Root Catalog] / Web-INF / Web.xml
Node Added content:
FAQServletl
Test.faQServlet
according to
URL-PATTERN
Gain
servlet-name,
According to
servlet-name
Gain
Servlet-Class ">
FAQServletl
/ servlet / faqservlet
The main meaning should be: When the URL is http: // [root] / servlet / faqservlet, the name of the servlet is FAQServletl, the server finds the servlet named FAQSERVLETL according to the FAQServlet, and positions through servlet-class test.faqservlet The location of the servlet.
4. Phenomenon: Browse the address http://127.0.0.1:8080/servlet/faqservlet, the browser opens a page, the effect is the same as XML, because the above response.setContentType ("text / xml"); if you need text / html It is HTML page, but it is necessary to make up HTML code.
5. It seems that the servlet can be used without deployment, and I don't know if I have been studying.
Taglib deployment process:
1. [Root Catalog] / Web-INF / CLASS / TEST / HELLO / New HelloTag.Java
2. HelloTag.java Enter the content:
Package test.hello;
Import javax.servlet.jsp.jspexception;
Import javax.servlet.jsp.jsptagexception;
Import javax.servlet.jsp.tageXt.tagsupport;
Public class hellotag extends tagsupport {
Public hellotag () {
}
PUBLIC INT DOENDTAG () THROWS JSPEXCEPTION {
Try {
PageContext.get (). Print ("Hello World!");
} catch (exception ex) {
EX.PrintStackTrace ();
}
Return Skip_body;
}
Public void release () {
Super.release ();
}
}
Taglib should be derived from tagsupport.
3. [Root Catalog] / Web-INF / Directory New Mytaglib.TLD
4. Mytaglib.tld Enter the content:
1.0
1.1
MyTablib
/ MyTaglib
Hello
Test.hello.hellotag
EMPTY
Just Says Hello
It feels that the main two content is
When referenced in JSP, tag / tagclass is Taglib corresponding to Class's reference, and corresponds to the Package above Java.
5. [Root Catalog] / Test / New HelloTag.jsp, and enter the content:
<% @ Taglib Uri = "/ MyTaglib" prefix = "mm"%>
This should be okay. Call the classes and functions inside Taglib via mm. It seems that Java Bean can also achieve the same function, and it seems that Java Bean is more flexible, start school, and needs further understanding.
6. Phenomenon: Browse address http: // [root] /test/hellotag.jsp, page display: "Hello World!"
7. TLD seems to have a method of deploying a Static function in a Taglib class, there is no attempt. This method should have no alternative ways in java beans! summary:
1. Website construction in Java can have so many levels, significantly increase flexibility, and you can use all of Java class libraries, this website, undoubtedly, can be very powerful.
2. Use JAD and other anti-compilation tools, you can compile Java's target file Class, so that you have to learn other people's results, it is very easy, but it is also unsafe.
3. Java supports support in different systems, increasing the reuse of the program, achieving the same function, using different class libraries, written a few times a few times.
4. Java includes the configuration of the derived tool environment and complicated, it is really trouble. J Builder is very easy to use, in order to thoroughly understand Java, learn about different deployment steps or necessary.