• [DRP]-index.jsp 页面到另一个页面 servlet如何配置


    JSP页面

    <%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
    <%
    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>
       <a href="servlet/JstlElServlet">测试EL表达式</a><br>
      </body>
    </html>

    然后去web.xml里找:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" 
        xmlns="http://java.sun.com/xml/ns/j2ee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    
        <servlet>
            <servlet-name>JstlElServlet</servlet-name>
            <servlet-class>com.bjpowernode.jstl.JstlElServlet</servlet-class>
        </servlet>    
        
        <servlet-mapping>
            <servlet-name>JstlElServlet</servlet-name>
            <url-pattern>/servlet/JstlElServlet</url-pattern>        
        </servlet-mapping>
        
    </web-app>

    然后找java类:

    package com.bjpowernode.jstl;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class JstlElServlet extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            request.setAttribute("hello", "hello world");
            
            request.getRequestDispatcher("/WEB-INF/jstl_el.jsp").forward(request, response);
        }
    
    }

    跳转到jstl_jsp页面

    <%@ page language="java" contentType="text/html; charset=GB18030"
        pageEncoding="GB18030"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
    <title>Insert title here</title>
    </head>
    <body>
       <h1>测试EL表达式</h1>
       <hr>
       <li>普通字符串</li><br>
       hell0(jsp脚步):<%=request.getAttribute("hello") %><br>
    </body>
    </html>

    总结:努力让那些看不起你,抛弃你的人后悔!

  • 相关阅读:
    为什么需要配置环境变量
    Highcharts使用简例 + 异步动态读取数据
    使用SQL检测死锁
    2015.12.21-2015.12.25单词
    SQL Server锁定【2015.12.17】
    SQL SERVER 并发【2015.12.16】
    SQL闲杂知识点汇总【2015年12月】
    键和约束【2015.12.11】
    [笔记]聚集索引和非聚集索引相关知识点
    论Top与ROW_NUMBER读取第一页的效率问题
  • 原文地址:https://www.cnblogs.com/yinweitao/p/5697420.html
Copyright © 2020-2023  润新知