首页 > 其他分享 >servJump extends HttpServlet //request.getRequestDispatcher //response.sendRedirect("http

servJump extends HttpServlet //request.getRequestDispatcher //response.sendRedirect("http

时间:2023-05-20 12:32:43浏览次数:64  
标签:http request getRequestDispatcher HttpServlet println import servlet response ou

package com.test;
import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Map;import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;import org.apache.log4j.Logger;
public class servJump extends HttpServlet {
  private static Logger log = Logger.getLogger(servJump.class); 
  private static int i=0;
  /**
   * Constructor of the object.
   */
  public servJump() {
   super();
  } /**
   * Destruction of the servlet. <br>
   */
  public void destroy() {
   super.destroy(); // Just puts "destroy" string in log
   // Put your code here
  } /**
   * The doGet method of the servlet. <br>
   *
   * This method is called when a form has its tag value method equals to get.
   * 
   * @param request the request send by the client to the server
   * @param response the response send by the server to the client
   * @throws ServletException if an error occurred
   * @throws IOException if an error occurred
   */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {  response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
   out.println("<HTML>");
   out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
   out.println("  <BODY>");
   out.print("    This is ");
   out.print(this.getClass());
   out.println(", using the GET method");
   out.println("  </BODY>");
   out.println("</HTML>");
   out.flush();
   out.close();
  } /**
   * The doPost method of the servlet. <br>
   *
   * This method is called when a form has its tag value method equals to post.
   * 
   * @param request the request send by the client to the server
   * @param response the response send by the server to the client
   * @throws ServletException if an error occurred
   * @throws IOException if an error occurred
   */
  public void doPost(final HttpServletRequest request, final HttpServletResponse response)
    throws ServletException, IOException {
 /*
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
   out.println("<HTML>");
   out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
   out.println("  <BODY>");
   out.print("    This is ");
   out.print(this.getClass());
   out.println(", using the POST method");
   out.println("  </BODY>");
   out.println("</HTML>");
   out.flush();
   out.close();
 */
   new Thread(new Runnable(){   @Override
    public void run() {
     // TODO Auto-generated method stub
     try {
      Thread.sleep(5000);
     } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
     
     Map<String, String> params = new HashMap<String, String>();  
     params.put("name", "name");  
     params.put("password", "password");           
     String loginUrl="http://localhost:8080/servletJump/servlet/servJump";
     String xml = HttpXmlClient.post(loginUrl, params);  
     log.info(xml);      
    }
    
   }).start();
   
   if(request.getParameter("name") != null){
    i=1; 
   }
   
   if(i==1)//
   {  
    //request.getRequestDispatcher("/Result.jsp").forward(request, response);
       response.sendRedirect("http://localhost:8080/servletJump/Result.jsp");
   }
   else
   {
    //request.getRequestDispatcher("/calcIng.jsp").forward(request, response);    
    response.sendRedirect("http://localhost:8080/servletJump/calcIng.jsp");   
   } }
 /**
   * Initialization of the servlet. <br>
   *
   * @throws ServletException if an error occurs
   */
  public void init() throws ServletException {
   // Put your code here
  }}

标签:http,request,getRequestDispatcher,HttpServlet,println,import,servlet,response,ou
From: https://blog.51cto.com/gjwrxz/6317429

相关文章

  • Fiddler抓包工具安装HTTPS证书
    安装好之后,打开Fiddler根目录,打开CMD执行以下内容makecert.exe-r-ssmy-n"CN=DO_NOT_TRUST_FiddlerRoot,O=DO_NOT_TRUST,OU=Createdbyhttp://www.fiddler2.com"-skysignature-eku1.3.6.1.5.5.7.3.1-h1-cyauthority-asha1-m120-b09/11/2022注意上面命令中,最后......
  • 为什么有了 HTTP 还要 RPC
    哈喽大家好,我是咸鱼随着互联网技术的发展,分布式架构越来越被人们所采用。在分布式架构下,为了实现复杂的业务逻辑,应用程序需要分布式通信实现远程调用而这时候就需要一种协议来支持远程过程调用,以便实现不同应用程序之间的数据交换和信息传递。其中常用的协议包括HTTP协议和RP......
  • Qt+QtWebApp开发笔记(二):http服务器日志系统介绍、添加日志系统至Demo测试
    前言  上一篇使用QtWebApp的基于Qt的轻量级http服务器实现了一个静态网页返回的Demo,网页服务器很重要的就是日志,因为在服务器类上并没有直接返回,所以,本篇先把日志加上。 Demo  下载地址  链接:https://pan.baidu.com/s/1BPVRLS07qk-WPi-txERKbg?pwd=1234......
  • 深入 Hyperf:HTTP 服务启动时发生了什么?
    当我们创建Hyperf项目之后,只需要在终端执行phpbin/hyperf.phpstart启动命令,等上几秒钟,就可以看到终端输出的Worker进程已启动,HTTP服务监听在9501端口的日志信息。[INFO]Worker#3started.[INFO]Worker#1started.[INFO]Worker#2started.[INFO]Worker#0......
  • Chrome更新全新设计的 HTTPS 图标
    导读HTTPS是一种用于安全地传输数据的网络协议。HTTPS是在HTTP协议的基础上添加了SSL/TLS协议,通过对数据进行加密,从而保证数据传输的安全性。HTTPS常用于保护敏感信息,如个人身份信息、银行账户信息、信用卡信息等。目前市面上所有的浏览器都会在与网站通过HTTPS......
  • Netty集成HTTP的GET和POST通讯
    核心就是ChannelInitializer的实现使用http消息解码器packagecom.coremain.handler;importio.netty.channel.ChannelInitializer;importio.netty.channel.socket.SocketChannel;importio.netty.handler.codec.http.HttpObjectAggregator;importio.netty.handler.codec......
  • Apipost Error: Invalid URI "http:///%20"
    1.情景展示使用Apipost调接口时,出现如上图所示的错误。2.具体分析去他们官网,帮助文档,连个搜索功能都没有,也是服了。说明这个请求地址有问题,但实际我把请求地址放到浏览器当中是可以正常访问的。3.解决方案百思不得其解。最后,发现:原来,是自己在复制URL的时候,前面多了一个......
  • 抓包工具Charles:(三)https协议的抓取
    当我们在抓包是,经常遇到https协议,抓取的内容不是乱码就是unknown。例如: 解决的办法很简单:第一步:在charles中安装ssl协议      第二步:  ......
  • https证书如何导入
    提问https证书如何导入回答C#生成自签名证书varrsa=RSA.Create();varx500Name=newX500DistinguishedName("CN=[通用名],O=[公司],OU=[单位]");varreq=newCertificateRequest(x500Name,rsa,HashAlgorithmName.SHA256,RSASignaturePadding.Pkcs1);varsan......
  • HTTP状态码的学习&记录
    一、什么是HTTP状态码?HTTP状态码是指在客户端向服务器发送请求时,服务器返回的响应状态码。二、HTTP状态码都有哪一些?客户端:指使用网络或分布式系统服务的终端用户设备或软件,通常是指桌面电脑、笔记本电脑、智能手机、平板电脑等计算机设备。服务端:指提供网络或分......