HttpServlet转发到 jsp 教学

Posted Xuxin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HttpServlet转发到 jsp 教学相关的知识,希望对你有一定的参考价值。

由于上一个星期研究关于作为唯一字段的账号来修改密码的问题,有一个问题一直很困扰,假如有A,B两个网页,A网页提交忘记密码验证信息,经过服务器处理后,允许修改密码,但是A网页输入的账号无法在B网页上收到,如果收不到,不能确定账号的唯一性,密码无法得到修改,或者会修改到别人的密码,安全性降低了,如果重写一遍或者把B网页的内容与A网页都放在一起,会有点笨拙,一点也不符合我的要求,研究了一天没有弄会,放弃后今天又重新试试手,一次成功了,我说的可能有点抽象,好了,接下来这里把详细教程与源码写出来,主要不懂还可以问我的,在这上面研究花了不少时间了,哎

源码:<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<form action="Good"method="post">

<input type="text"name="name">

<input type="submit"value="提交">

</form>

</body>

</html>

HttpServlet转发到 jsp 教学


源码:

package c; 

importjava.io.IOException; 

importjavax.servlet.ServletException;

importjavax.servlet.annotation.WebServlet;

importjavax.servlet.http.HttpServlet; 

importjavax.servlet.http.HttpServletRequest; 

import javax.servlet.http.HttpServletResponse; 

 

@WebServlet("/Good")// 准备数据库插入注册信息

public class Goodextends HttpServlet { 

    /**

       *

       */

      private static final long serialVersionUID= 1L;

      public void doGet(HttpServletRequestrequest, HttpServletResponse response)  

            throws ServletException,IOException { 

            request.setCharacterEncoding("utf-8");

            response.setHeader("Content-type","text/html;charset=UTF-8");

            response.setCharacterEncoding("utf-8");

            Stringst=request.getParameter("name");

        //Test数据打包            testjsp接收的杯子,杯子里有GoodGoodStudy,Day Day UP這些水

        request.setAttribute("Test",st); 

        //Test数据发送到Test.jap文件中 

       request.getRequestDispatcher("Test.jsp").forward(request,response);

 

    } 

    public void doPost(HttpServletRequestrequest, HttpServletResponse response) 

            throws ServletException,IOException { 

        doGet(request, response); 

    } 

 

HttpServlet转发到 jsp 教学

源码:

<%@ page language="java"import="java.util.*" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="UTF-8"%>

   <%

String path =request.getContextPath();

String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE html PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

 <base href="<%=basePath%>">

<title>Insert title here</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">

</head>

<body>

 <%

 String PAR=(String)request.getAttribute("Test");

  %>

  <%=PAR%>

</body>

</html>

下面给大家演示下:


大功告成,是不是学会了。

以上是关于HttpServlet转发到 jsp 教学的主要内容,如果未能解决你的问题,请参考以下文章

HttpServlet的转发和重定向

关于jsp页面中:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build P

jsp如何转发到其他域,如我的项目http://localhost/test/test.jsp 在这个界面如何转发到www.baidu.com?

新建 jsp异常,The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build P

JSP报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

index.jsp报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bui