• javaservlet配置问题


    web.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      
      <!-- 向Tomcat报告,我这个应用里面有这个servlet,名字叫做HelloServlet,具体的配置如下 -->
      
      <servlet>
              <servlet-name>HelloServlet</servlet-name>
              <servlet-class>com.servlet.zyz.HelloServlet</servlet-class>
      </servlet>
      <servlet-mapping>
              <servlet-name>HelloServlet</servlet-name>
              <url-pattern>/hello</url-pattern>
      </servlet-mapping>
    </web-app>

    HelloServlet.javapackage com.servlet.zyz;

    
    import java.io.IOException;
    
    import javax.servlet.Servlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    
    public class HelloServlet implements Servlet {
    
        public void destroy() {
            // TODO Auto-generated method stub
            
        }
    
        public ServletConfig getServletConfig() {
            // TODO Auto-generated method stub
            return null;
        }
    
        public String getServletInfo() {
            // TODO Auto-generated method stub
            return null;
        }
    
        public void init(ServletConfig arg0) throws ServletException {
            // TODO Auto-generated method stub
            
        }
    
        public void service(ServletRequest arg0, ServletResponse arg1)
                throws ServletException, IOException {
            // TODO Auto-generated method stub
            System.out.println("Hello Servlet start....");
            
        }
    
    
    }

    index.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
      </head>
      
      <body>
        This is my JSP page. <br>
      </body>
    </html>

    一纸高中万里风,寒窗读破华堂空。 莫道长安花看尽,由来枝叶几相同?
  • 相关阅读:
    上班5个月总结
    使用余弦定理计算两篇文章的相似性
    9月10日 小结
    软件测试
    《增长黑客》笔记
    统计学术语
    数据分析师:数据分析工作常见七种错误及其规避技巧(转自经管之家)
    输入一个日期,计算这个日期与 2018-03-12差多少天;
    求输入数字的阶乘 及加和 #s=1!+2!+3!+…..+n!
    列表去重
  • 原文地址:https://www.cnblogs.com/byczyz/p/11230278.html
Copyright © 2020-2023  润新知