Tutorial: Creating Struts Application in Eclipse
Tutorial: Creating Struts Application in Eclipse
Tutorial: Creating Struts Application in Eclipse
Eclipse
By Viral Patel on December 4, 2008
Featured, How-To, Struts, Tutorial
Note: If you looking for tutorial “Create Struts2 Application in Eclipse” Click here.
In this tutorial we will create a hello world Struts application in Eclipse editor. First let us see
what are the tools required to create our hello world Struts application.
We will implement a web application using Struts framework which will have a login screen.
Once the user is authenticated, (s)he will be redirected to a welcome page.
Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New
Project wizard screen.
After selecting Dynamic Web Project, press Next.
Write the name of the project. For example StrutsHelloWorld. Once this is done, select the
target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse
environment. After this press Finish.
Once the project is created, you can see its structure in Project Explorer.
Now copy all the required JAR files in WebContent -> WEB-INF -> lib folder. Create this folder
if it does not exists.
view source
print?
01 <servlet>
02 <servlet-name>action</servlet-name>
03 <servlet-class>
04 org.apache.struts.action.ActionServlet
05 </servlet-class>
06 <init-param>
07 <param-name>config</param-name>
08 <param-value>/WEB-INF/struts-config.xml</param-value>
09 </init-param>
10 <load-on-startup>1</load-on-startup>
11 </servlet>
12 <servlet-mapping>
13 <servlet-name>action</servlet-name>
14 <url-pattern>*.do</url-pattern>
15 </servlet-mapping>
Here we have mapped url *.do with the ActionServlet, hence all the requests from *.do url will
be routed to ActionServlet; which will handle the flow of Struts after that.
We will create package strutcures for your project source. Here we will create two packages, one
for Action classes (net.viralpatel.struts.helloworld.action) and other for Form
beans(net.viralpatel.struts.helloworld.action).
Also create a class LoginForm in net.viralpatel.struts.helloworld.action with following content.
view source
print?
01 package net.viralpatel.struts.helloworld.form;
02
03 import javax.servlet.http.HttpServletRequest;
04 import org.apache.struts.action.ActionErrors;
05 import org.apache.struts.action.ActionForm;
06 import org.apache.struts.action.ActionMapping;
07 import org.apache.struts.action.ActionMessage;
08
09 public class LoginForm extends ActionForm {
10
11 private String userName;
12 private String password;
13
14 public ActionErrors validate(ActionMapping mapping,
15 HttpServletRequest request) {
16
17 ActionErrors actionErrors = new ActionErrors();
18
19 if(userName == null || userName.trim().equals("")) {
actionErrors.add("userName", new
20
ActionMessage("error.username"));
21 }
22 try {
23 if(password == null || password.trim().equals("")) {
actionErrors.add("password", new
24
ActionMessage("error.password"));
25 }
26 }catch(Exception e) {
27 e.printStackTrace();
28 }
29 return actionErrors ;
30 }
31
32 public String getUserName() {
33 return userName;
34 }
35 public void setUserName(String userName) {
36 this.userName = userName;
37 }
38 public String getPassword() {
39 return password;
40 }
41 public void setPassword(String password) {
42 this.password = password;
43 }
44 }
LoginForm is a bean class which extends ActionForm class of struts framework. This class will
have the string properties like userName and password and their getter and setter methods. This
class will act as a bean and will help in carrying values too and fro from JSP to Action class.
Let us create an Action class that will handle the request and will process the authentication.
Create a class named LoginAction in net.viralpatel.struts.helloworld.action package. Copy paste
following code in LoginAction class.
view source
print?
01 package net.viralpatel.struts.helloworld.action;
02
03 import javax.servlet.http.HttpServletRequest;
04 import javax.servlet.http.HttpServletResponse;
05
06 import net.viralpatel.struts.helloworld.form.LoginForm;
07
08 import org.apache.struts.action.Action;
09 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionForward;
11 import org.apache.struts.action.ActionMapping;
12
13 public class LoginAction extends Action {
14
15 public ActionForward execute(ActionMapping mapping, ActionForm form,
16 HttpServletRequest request, HttpServletResponse response)
17 throws Exception {
18
19 String target = null;
20 LoginForm loginForm = (LoginForm)form;
21
22 if(loginForm.getUserName().equals("admin")
23 && loginForm.getPassword().equals("admin123")) {
24 target = "success";
25 request.setAttribute("message", loginForm.getPassword());
26 }
27 else {
28 target = "failure";
29 }
30
31 return mapping.findForward(target);
32 }
33 }
In action class, we have a method called execute() which will be called by struts framework
when this action will gets called. The parameter passed to this method are ActionMapping,
ActionForm, HttpServletRequest and HttpServletResponse. In execute() method we check if
username equals admin and password is equal to admin123, user will be redirected to Welcome
page. If username and password are not proper, then user will be redirected to login page again.
We will use the internationalization (i18n) support of struts to display text on our pages. Hence
we will create a MessagesResources properties file which will contain all our text data. Create a
folder resource under src (Right click on src and select New -> Source Folder). Now create a
text file called MessageResource.properties under resources folder.
Copy the following content in your Upadate:struts-config.xml MessageResource.properties file.
view source
print?
1 label.username = Login Detail
2 label.password = Password
3 label.welcome = Welcome
4
5 error.username =Username is not entered.
Create two JSP files, index.jsp and welcome.jsp with the following content in your WebContent
folder.
index.jsp
view source
print?
01 <%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
02 <%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
03
04 <html>
05 <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
06
8859-1">
<title>Login page | Hello World Struts application in
07
Eclipse</title>
08 </head>
09 <body>
10 <h1>Login</h1>
11 <html:form action="login">
12 <bean:message key="label.username" />
13 <html:text property="userName"></html:text>
14 <html:errors property="userName" />
15 <br/>
16 <bean:message key="label.password"/>
17 <html:password property="password"></html:password>
18 <html:errors property="password"/>
19 <html:submit/>
20 <html:reset/>
21 </html:form>
22 </body>
23 </html>
welcome.jsp
view source
print?
01 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
02 pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
03
"http://www.w3.org/TR/html4/loose.dtd">
04 <html>
05 <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
06
8859-1">
<title>Welcome page | Hello World Struts application in
07
Eclipse</title>
08 </head>
09 <body>
10 <%
11 String message = (String)request.getAttribute("message");
12 %>
13 <h1>Welcome <%= message %></h1>
14
15 </body>
16 </html>
Now create a file called struts-config.xml in WEB-INF folder. Also note that in web.xml file we
have passed an argument with name config to ActionServlet class with value /WEB-INF/struts-
config.xml.
view source
print?
01 <?xml version="1.0" encoding="ISO-8859-1" ?>
02
03 <!DOCTYPE struts-config PUBLIC
04 "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
05 "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
06
07 <struts-config>
08 <form-beans>
09 <form-bean name="LoginForm"
10 type="net.viralpatel.struts.helloworld.form.LoginForm" />
11 </form-beans>
12
13 <global-exceptions>
14 </global-exceptions>
15 <global-forwards></global-forwards>
16
17 <action-mappings>
<action path="/login" name="LoginForm" validate="true"
18
input="/index.jsp"
19 type="net.viralpatel.struts.helloworld.action.LoginAction">
20 <forward name="success" path="/welcome.jsp" />
21 <forward name="failure" path="/index.jsp" />
22 </action>
23 </action-mappings>
24
<message-resources parameter="resource.MessageResource"></message-
25
resources>
26
27 </struts-config>
And, that’s it :) .. We are done with our application and now its turn to run it. I hope you have
already configured Tomcat in eclipse. If not then:
Open Server view from Windows -> Show View -> Server. Right click in this view and select
New -> Server and add your server details.
To run the project, right click on Project name from Project Explorer and select Run as -> Run
on Server (Shortcut: Alt+Shift+X, R)
Login Page
Welcome Page
See also:
Spring 3 MVC – Introduction to Spring 3 MVC Framework
Struts2 Validation Framework Tutorial with Example
Inner classes in Java, the mystery within.
RESTful Web Service tutorial: An Introduction for beginners
Creating & Parsing JSON data with Java Servlet/Struts/JSP
Tutorial: Creating JavaServer Faces JSF application in Eclipse
Struts Validation Framework tutorial with example.
Struts DispatchAction Tutorial with Example in Eclipse.
Thanks Viral,
The explanation and information is very apt.
Very useful.
Informative post.
Here’s a similar tutorial, but for the latest version of struts 2 – Create Struts 2 – Hello
World Application
If you’re (still) doing Struts, you should check out Oracle Workshop for WebLogic. It is
the best Struts tool by far, includes many examples and can do much much more than
Eclipse WTP. It is not WebLogic specific. And, it’s free.
@Veera : Nice to see your Struts-2 tutorial. You will see more tutorials on similar line
here on viralpatel.net
@Zviki : Thanks for your comment. Will definitely check Oracle Workshop for
WebLogic.
@Zviki I suggest having a look at IntelliJ IDEA’s support for Struts 2, in my opinion it is
one of the best. It’s not free, though.
hi did anyone try this with WASCE server? iam doing in it and evrything looks fine
except that when i clikc on submit it says that the resource/login is not found..
——————————————————————————–
message
description The server encountered an internal error () that prevented it from fulfilling
this request.
exception
root cause
root cause
mayank wrote on 7 January, 2009, 18:14
——————————————————————————–
message
description The server encountered an internal error () that prevented it from fulfilling
this request.
exception
9:
10: Login
11:
12:
13:
14:
15:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java
:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
root cause
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
many thanks
mayank
did u mean that paste the above content in MessageResource.properties file? or struts-
config.xml file?
Thanks again.
Hi
I am getting following error please help…
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans
collection
at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:712)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:500)
at org.apache.jsp.index_jsp._jspx_meth_html_form_0(org.apache.jsp.index_jsp:132)
at org.apache.jsp.index_jsp._jspx_meth_html_html_0(org.apache.jsp.index_jsp:108)
at org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:75)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173
)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213
)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(
Http11Protocol.java:744)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerTh
read.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Hi,
I am getting Error 404–Not Found From RFC 2068 Hypertext Transfer Protocol —
HTTP/1.1:
10.4.5 404 Not Found . I have double checked web.xml and struts-config.xml. I would
appreicate, if anyone can help me.
You should have take the time to make this tutorial with the latest version of struts 1 :
v1.3.10
The version 1.2, on which is based this tutorial, has been released for more than 4 years !
The branch 1.3 which split struts.jar into multiple modules has been release in two years !
Thanks
Sample
FrEE wrote on 17 February, 2009, 12:54
Hi,
http://www.interview-questions-tips-forum.net/index.php/Apache-Struts/Struts2-
example-tutorial/My-First-example-using-Apache-Struts2
I m not able to find jar files u mentioned above.Can u provide me the exact path..
Greetings!
I found your post very educating. This is the first sample struts application I created using
eclipse.
However, I kept getting the error saying the message was not found in the key bundle.
I tried many things but I got the same error. Finally I modified the entry in the struts-
config.xml to
from what you mentioned. It did the trick.
I’m using struts 1.3, jdk 6 and eclipse ganymede.. hope that helps.
Baran wrote on 2 March, 2009, 14:20
Hello There,
I am fairly new to Struts, I was wondering if anyone can post or preferably mail me some
materila about how to handle database connectivity in Struts. I am working on JNDI but I
guess this won\\\’t be helpful if I have a shared apache tomcat server as that won\\\’t let
me access the server.xml file.
my id is baran.khan @ gmail.com
I am preety new to struts. I want to know how to remove the error Missing message for
key \"label.username\"? I have created a package name resource in src and created a file
in it with the name MessageResource.properties. What changes i need to make in my
struts-config.xml?
Hi Payal,
I am not sure if I got your problem. What I understand is that you want to remove the
error messages generated from keys that are missing in your bundle MessageResource
file. If this is the case then you can use null attribute in <message-resources> tag in
struts-config.xml file.
null attribute will control the messages, If true, references to non existing messages
results in null and If false, references to non existing messages result in warning message
like
???KeyName???
Hope this will solve your query.
But, I was having the same error “Missing message for key “label.username” and I
moved the file MessageResource to the folder WEB-INF->classes->resource. That did
the trick.
Could anyone help me to solve the following error? I have checked the struts-config and
web.xml . But I cannot find the error.please…
,Grace
The server encountered an internal error () that prevented it from fulfilling this request.
Hi..
Kiran
I have done everything as told here.I am using SDE 3.1 and I am getting this exception
on runing the application.Can anyone help?
help me,
I am beginner programmer, I got exception in ur tutorial as this
——————————————————————————–
message
description The server encountered an internal error () that prevented it from fulfilling
this request.
exception
10: <body>
11: <h1>Login</h1>
12: <html:form action=\"login\">
13: <bean:message key=\"label.username\" />
14: <html:text property=\"userName\"></html:text>
15: <html:errors property=\"userName\"/>
16: <br/>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java
:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
javax.servlet.ServletException: Missing message for key \"label.username\"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.j
ava:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java
:774)
org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
——————————————————————————–
Apache Tomcat/5.5.27
please help me
I already copy
label.username = Login Detail
label.password = Password
label.welcome = Welcome
error.username =Username is not entered.
to the resource folder, but the exception still occured….
please help me
@sarwo edi: nice to see that your problem got solved :) by the way. where was the
problem exactly? I guess your properties file was not getting referred properly?
txh
<message-resources parameter=\"resource.MessageResource\"></message-resources>
should be
<message-resources parameter=\"MessageResource\"></message-resources>
Muchas gracias!!! a Viral por el tutorial y también a Davinchi porque dió la solución al
mismo problema que tenía yo!!!!
But, I was having the same error “Missing message for key “label.username” and I
moved the file MessageResource to the folder WEB-INF->classes->resource. That did
the trick.
i am getting error
Struts 1
Welcome
Learning
Roadmap
Releases
Documentation
User Guide
FAQs and HOWTOs
Release Notes
Javadoc
DTDDoc
Support
Components
Struts Apps
Struts EL
Struts Extras
Struts Faces
Struts Scripting
Struts Taglib
Struts Tiles
Project Documentation
Project Information
Project Reports
* DISCLAIMER - This simple How-To shows you one of many ways to setup a working project
using
the Struts framework. This is mainly geared toward Struts users who are new to Eclipse, and
don't want to spend a lot of time figuring out the differences between their old IDE (if any)
and this one.
I will also apologize ahead of time for the formatting of this page.
In this How-To, I will demonstrate (using Eclipse 2.0.1) how to setup, compile, run,
and debug the struts-mailreader web application that is part of the Struts Applications subproject.
Next, I will modify the code to pull some data from a MySql database using the popular
relational mapping tool OJB. (This is actually quite simple)
Let's get started
Before we begin, you will need to create a directory somewhere to store your project.
I typically use C:\personal\development\Projects\(some project)
Once that's done, extract the struts-mailreader.war to that directory
(using your favorite zip utility)
Delete the META-INF folder because this will be created during the build/jar/war process.
Add a build.xml file to the project root. I use something like this:
<property file="./build.properties"/>
<!--
This build script assumes Tomcat 5 is the servlet
container.
Modify as necessary if a different container is being
used.
-->
<property name="tomcat.home"
value="${env.CATALINA_HOME}"/>
<property name="servlet.jar"
value="${tomcat.home}/common/lib/servlet-api.jar"/>
<property name="jsp.jar"
value="${tomcat.home}/common/lib/jsp-api.jar"/>
<property name="deploy.dir"
value="${tomcat.home}/webapps"/>
<property name="build.compiler" value="modern"/>
<property name="build.dir" value="./WEB-INF/classes" />
<property name="src.dir" value="./WEB-INF/src"/>
<property name="war.file" value="struts-mailreader"/>
<property name="war.file.name" value="${war.file}.war"/>
<path id="project.class.path">
<fileset dir="./WEB-INF/lib/">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${src.dir}"/>
<pathelement path="${servlet.jar}"/>
<pathelement path="${jsp.jar}"/>
</path>
<target name="clean">
<delete dir="${build.dir}" includeEmptyDirs="true" />
</target>
<target name="prep">
<mkdir dir="${build.dir}"/>
</target>
<target name="compile">
<javac srcdir="${src.dir}"
destdir="${build.dir}"
debug="on"
deprecation="on">
<include name="**/*.java"/>
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="cleanWebApp">
<delete file="${deploy.dir}/${war.file.name}" />
<delete dir="${deploy.dir}/${war.file}"
includeEmptyDirs="true" />
</target>
<target name="war">
<war warfile="${war.file.name}"
webxml="./WEB-INF/web.xml">
<fileset dir="./" includes="**/*.*" excludes="*.war,
**/*.nbattrs, web.xml, **/WEB-INF/**/*.*,
**/project-files/**/*.*"/>
<webinf dir="./WEB-INF" includes="**/*"
excludes="web.xml, **/*.jar, **/*.class"/>
<lib dir="./WEB-INF/lib"/>
<classes dir="${build.dir}"/>
<classes dir="${src.dir}">
<include name="**/*.properties"/>
</classes>
</war>
</target>
<target name="deploy">
<copy todir="${deploy.dir}">
<fileset dir="./" includes="${war.file.name}"/>
</copy>
</target>
</project>
1. Create a new project.
2. New Java Project
12. Compilation warnings and errors are detected immediately. In this screenshot, I drill down
into the source folder, package, file, class, and double click on the method....which
brings up the source editor. I hover the mouse over the offending warning to see
a description of what's wrong.
13. I changed ApplicationConfig to ModuleConfig, then saved and now I see new errors.
You can right click and import ModuleConfig right from the error.
14. A quick look at the import section.
17. From the Package Explorer, right click your build.xml and run Ant:
18. Is this cool or what?
19. Uh Oh!
20. Quick look at what jars are being used to process my build.
21. I simply removed all the existing jars from the IDE's Ant configuration and
added all from my own installation.
22. Can't forget that last one
Installing Tomcat
This is a brief "how-to" for installing Tomcat on a Windows PC.
Installing Java
Tomcat requires java in order to run. If your computer already has java installed, you can
probably skip this step. However, make sure you have a recent version of java. Here I provide
instructions for installing version 1.4.2 of the Java 2 Platform, Standard Edition (J2SE).
Here are the steps for setting the environment variable on my computer (Windows XP
Professional). The steps will probably be similar for other Windows computers.
Installing Tomcat
After setting the JAVA_HOME environment variable, you can install tomcat.
Running Tomcat
Here are the steps to see if Tomcat has been successfully installed
1. Start Tomcat by finding its start program in the Programs Menu (located in the Start menu).
Look under Apache Tomcat 4.1 and select "Start Tomcat".
2. Open a Web browser and type in the following URL:
o http://localhost:8080/
At this point, you should see the Tomcat home page, which is provided by the Tomcat Web
server running on your computer. Note: if your computer has an internet name or an IP number,
you may access your Tomcat server anywhere on the internet by substituting localhost with the
full name or IP number.
To shut down your server and remove the Console window, select "Stop Tomcat" in the same
menu of where you selected "Stop Tomcat".
Tomcat 4: c:\tomcat4\common\lib\servlet.jar
in addition to the servlet JAR file, you also need to put your development directory in the
CLASSPATH. Although this is not necessary for simple packageless servlets, once you gain
experience you will almost certainly use packages. Compiling a file that is in a package and that
uses another class in the same package requires the CLASSPATH to include the directory that is at
the top of the package hierarchy. In this case, that's the development directory I just discussed.
Forgetting this setting is perhaps the most common mistake made by beginning servlet
programmers!
Finally, you should include "." (the current directory) in the CLASSPATH. Otherwise, you will
only be able to compile packageless classes that are in the top-level development directory.
Here are two representative methods of setting the CLASSPATH. They assume that your
development directory is C:\Servlets+JSP. Replace install_dir with the actual base installation
location of the server. Also, be sure to use the appropriate case for the filenames, and enclose
your pathnames in double quotes if they contain spaces.
Note that these examples represent only one approach for setting the CLASSPATH. Many Java
integrated development environments have a global or project-specific setting that
accomplishes the same result. But these settings are totally IDE-specific and won't be discussed
here. Another alternative is to make a script whereby -classpath ... is automatically
appended onto calls to javac.
Windows NT/2000/XP. You could use the autoexec.bat file as above, but a more common
approach is to use system settings. On WinXP, go to the Start menu and select Control Panel,
then System, then the Advanced tab, then the Environment Variables button. On Win2K/WinNT,
go to the Start menu and select Settings, then Control Panel, then System, then Environment.
Either way, enter the CLASSPATH value from the previous bullet.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
c:\ Tomcat4\webapps\webdir\WEB-INF\classes\HelloWorld.java
From someone who want to how to config tomcat, please refer to:
http://www.coreservlets.com/Apache-Tomcat-Tutorial/