First, write a simple servlet program 1. Or use HelloWorld as an example, we write a HelloWorld.java, the code is as follows: package hello; // Note the name of the package, it will be useful.
Import java.io. *; import javax.servlet. *; import javax.servlet.http. *;
public class HelloWorld extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {response.setContentType ( "text / html"); PrintWriter out = response.getWriter (); out.println ( ""); out .println (""); out.println (""); out.println (""); out.println ("" "); Out.println (" Hello World! "); Out.println (""); out.println ("");}} We temporarily save the source file to the C: / servlet directory
2. Compile the source file. Here, you need to pay attention to HelloWorld to use the Javax.Servlet package, so you need to explain in ClassPath, otherwise it will be compiled. The specific compilation command is: javac -classpath "% classpath%;% jboss_home% / server / default / lib / javax.servlet.jar" HelloWorld.java] To explain: 1)% classpath% refers to settings in environment variables Good class library path, if you have no settings, then create a new environment variable named ClassPath in the environment variable, which is specified as a JDK directory /jRE/lib/rt.jar. If you want to put the javax.servlet packet path, add ";% jboss_home / server / default / lib / javax.servlet.jar" behind RT.jar. 2)% jboss_home% refers to the installation directory of JBoss, you can also create a JBoss_home variable in the environment variable to specify the JBoss installation directory.
If there is no accident, the compiler will pass normally, you can see a HelloWorld.class file in the C: / Servlet directory.
Second, write an XML configuration file code as follows: XML Version = "1.0" Encoding = "UTF-8"?>
Save the file to the C: / servlet directory, named Web.xml.
Third, configure the deployment directory 1. First create a web-inflicide under the C: / Servlet, and put the web.xml file in the directory. 2. Create a class content directory in the web-inflicity, put it in the compiled helloWorld.class file
Fourth, WAR files for making and deploying Remember the JAR program used when testing JSP last time? This time we use it to generate a deployed WAR file. Under C: / Servlet, execute JAR CVF Hello.war *. *, Soon generated a file called Hello.war, then copy hello.war to JBoss installation directory / server / default / deploy / down completion deploy.
V. Test in the address bar of the browser. HTTP: // localhost: 8080 / hello / helloworld If the HelloWorld word appears, the deployment is successful.