• 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>

    一纸高中万里风,寒窗读破华堂空。 莫道长安花看尽,由来枝叶几相同?
  • 相关阅读:
    单循环判断数组中是否有存在重复值
    【Moss2010系列】利用BCS进行业务数据集成(1)
    状态压缩
    矩阵快速幂
    高精度加法
    旋转treap
    bitset
    快速幂
    splay
    考试注意
  • 原文地址:https://www.cnblogs.com/byczyz/p/11230278.html
Copyright © 2020-2023  润新知