日期:2014-05-18  浏览次数:20637 次

doPost和doGet方法区别







package com.login.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ExitServlet extends HttpServlet {

/**
 * 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(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session=request.getSession();
session.invalidate();
response.sendRedirect("Login.jsp");
}



}



HTTP method GET is not supported by this URL


ExitServlet回传login.jsp时出了错误 为什么只能使用doGet()方法


------解决方案--------------------
引用:
谢谢各位 弄清楚了 应该是<a> 标签自动调用HttpServlet的doGet()方法

a标签发送的url字符串链接,就是get请求。。

------解决方案--------------------
楼上说的对,
a标签发送的url字符串链接,就是get请求。。
如果楼主实在想用doPost方法,
就在doGet方法中加一句
this.doPost(request, response);

就可以了。