Learn EJB for JBoss3.2 Notes (3) Test servlet

zhaozj2021-02-16  57

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: HelloWorld Hello. HelloWorld HelloWorld / helloworld Please note that each tag must be lowercase, otherwise it will be wrong. See the hello.helloworld ? The Hello is the package we just established. This shows that you can include multiple packages, but you can access these classes as you can explain the package corresponding to the class between the .

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.

转载请注明原文地址:https://www.9cbs.com/read-22270.html

New Post(0)