The simplest way to build a JSP environment is
Java + Tomcat supports JSP code.
1. First, we need to download the JDK and tomcat installation packages.
JDK http://www.oracle.com/technetwork/java/index.html.
Tomcat http://tomcat.apache.org/
2. Configure Java environment variables
Java_home = c: \ Program Files \ Java \ jdk1.7.0 \
Classpath =.; % java_home % \ Lib \ DT. jar; % java_home % \ Lib \ tools. jar;
Path = % java_home % \ bin;
Then, you can enter the Java-version javac and other commands in the command line. If all the commands are OK, the Java environment variables are properly configured.
3. Configure Tomcat Environment Variables
Tomcat_home = D: \ tomcat7
Then Copy D: \ tomcat7 \ Lib \ servlet-api.jar to the C: \ Program Files \ Java \ jdk1.7.0 \ JRE \ Lib \ ext \ directory
4. Start the Tomcat Service
If it is normal, a tomcat service will be started to access http: // localhost: 8080 /.
Now the environment has been set up
Two test items
1. Create a MyApp file under D: \ tomcat7 \ webapps
Then create a new WEB-INF folder
Create a web. xml file in the folder
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-appPUBLIC"-//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><servlet><servlet-name>HelloWorld</servlet-name><servlet-class>test.HelloWorld</servlet-class></servlet><servlet-mapping><servlet-name>HelloWorld</servlet-name><url-pattern>/HelloWorld</url-pattern></servlet-mapping></web-app>
Create a test JSP page named index. jsp under MyApp
At this time, you can view the current time in http: // localhost: 8080/MyApp/index. jsp in the browser, indicating that the execution is successful.
2. Create your own Servlet
Create helloworld. Java under the D: \ tomcat7 \ webapps \ MyApp \ WEB-INF \ Classes \ test directory
package test;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HelloWorld extends HttpServlet{public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("
After the compilation is successful by using javac helloworld. Java
Add in Web. xml
<servlet><servlet-name>HelloWorld</servlet-name><servlet-class>test.HelloWorld</servlet-class></servlet><servlet-mapping><servlet-name>HelloWorld</servlet-name><url-pattern>/HelloWorld</url-pattern></servlet-mapping>
We have already written this.
Http: // localhost: 8080/MyApp/helloworld enter this link and you will be able to see the big helloworld.
3. Create your own Java Bean
Go to D: \ tomcat7 \ webapps \ MyApp \ WEB-INF \ Classes \ test
Create testbean. Java
Then use javac testbean. Java to compile
Then, a new JSP file is created under MyApp.
Testbean. jsp
<%@ page import="test.TestBean" %>
Enter http: // localhost: 8080/MyApp/testbean. jsp to output a row of results.
The basic Tomcat + Java environment has been set up, enjoy
This article references http://huangshaomao.blog.163.com/blog/static/4389660920091534543466/