1.
Tomcat:
1 Apache Tomcat 8.0.36
(http://tomcat.apache.org/download-80.cgi#8.0.36)
2 D ( d:\apache-tomcat-8)
3 Eclipce Environment
- Servers
- No servers are available. .
- Tomcat v8.0 Server .
4 Apache installation Directory Finish.
5 Tomcat v8.0 Server at localhost [Stopped, Republish] Servers.
6 Server Start.
:
. URL: http://localhost:8080/
:
1 Eclipce Dynamic Web project. .
2 Finish
:
1 , New-Servlet
2
URL mapping.
3
4 doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
// Actual logic goes here.
PrintWriter out = response.getWriter();
out.println("<h1>" + "hello from [ " + request.getRequestURI() + "]</h1>");
}
5 . Run As Run on Server
:
6 , http://localhost:8080/adp/test
7 Web.xml /WEB-INF.
Eclipse. ADP-EE , Java EE Tools-Generate Deployment Descriptor Stub. web.xml.
web.xml :
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation= "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version= "3.1" >
<display-name>ADP-EE</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
|
|
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>by.bsac.adp.pz1.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/Servlet1</url-pattern>
</servlet-mapping>
</web-app>
:
http://localhost:8080/ADP-EE/Servlet1
, MIME-, mapping JSP, , . , . 3.0 , .
. , HTML- .
:
package by.bsac.pz1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class TestServlet
*/
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final String CONTENT_TYPE =
"text/html; charset=windows-1251";
public void init() throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet_2</title></head>");
out.println("<body bgcolor='#00ff00'>");
out.println("</body>");
out.println("</html>");
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
public void destroy() {
}
}
:
1. , HTML- "P1". " : ".
2. , HTML- "P1" "Submit". "Submit" HTML-, P1, , .
3. * , HTML- 1 "Submit". "Submit" HTML- 2 "Submit". 3 .
|
|