zoukankan      html  css  js  c++  java
  • [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>

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

  • 相关阅读:
    利用Node.js的Net模块实现一个命令行多人聊天室
    JS判断鼠标进入容器方向的方法和分析window.open新窗口被拦截的问题
    Node.js:进程、子进程与cluster多核处理模块
    Node.js:理解stream
    Node.js:Buffer浅谈
    Node.js:OS模块
    一个unsigned int 数的二进制表示中有多少个1
    一个栈的入栈序列为ABCDEF,则不可能的出栈序列是
    文件操作:获取一个文件行数的方法
    利用sourceinsight宏(Quicker.em)提高编码效率和质量
  • 原文地址:https://www.cnblogs.com/yinweitao/p/5697420.html
Copyright © 2011-2022 走看看