码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-07-22 23:01:55      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

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>

 

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

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

标签:

原文地址:http://www.cnblogs.com/yinweitao/p/5697420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!