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()方法
解决方案 »
- javascript如何遍历后台request传过来的List对象
- file类可以远程创建文件吗??
- tomcat 启动报错 ERROR [org.springframework.web.context.ContextLoader] -
- 为啥是Math.sqrt(i)
- 如何高效率的实现以下的问题?
- 关于FlippingBook逼真flash翻页效果问题,如何自动翻页,急求!!!!!
- struts2上传文件出现问题
- 关于TOMCAT问题,望大家都来看看
- 急~在websphere如何发布EAR包?
- java可以做电子邮件系统吗?
- jsp里面table有行数据怎么上传给action 求高手指点!!!
- java 菜单权限
什么意思 service方法不是servlet类的吗。。 现在是重写HttpServlet本人菜鸟 求指点
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"></head><body>
<%=request.getAttribute("Loginerror")==null?"":request.getAttribute("Loginerror") %>
<form action="LoginServlet" method="post">
username:<input type="text" name="username"><br>
upassword:<input type="password" name="upassword"><br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>LoginServlet
package com.login.controller;import java.io.IOException;
import java.io.PrintWriter;import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;import com.login.model.*;
public class LoginServlet 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 {
String username=request.getParameter("username");
String password=request.getParameter("upassword");
if(username!=null&&password!=null){
if(username.equals("a")&&password.equals("123")){
User user=new User(username, password);
HttpSession session=request.getSession(true);
session.setAttribute("userinfo", user);
request.getRequestDispatcher("LoginOK.jsp").forward(request, response);
return;
}
else{
request.setAttribute("Loginerror", "loginerror");
request.getRequestDispatcher("Login.jsp").forward(request, response); }
}else{
response.sendRedirect("Login.jsp");
} }}LoginOK.jsp<%@page import="com.login.model.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
hello <%=((User)session.getAttribute("userinfo")).getNameString() %>
<br>
<a href="ExitServlet">exit</a>
</body>
</html>
LoginServlet.javapackage com.login.controller;import java.io.IOException;
import java.io.PrintWriter;import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;import com.login.model.*;
public class LoginServlet 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 {
String username=request.getParameter("username");
String password=request.getParameter("upassword");
if(username!=null&&password!=null){
if(username.equals("a")&&password.equals("123")){
User user=new User(username, password);
HttpSession session=request.getSession(true);
session.setAttribute("userinfo", user);
request.getRequestDispatcher("LoginOK.jsp").forward(request, response);
return;
}
else{
request.setAttribute("Loginerror", "loginerror");
request.getRequestDispatcher("Login.jsp").forward(request, response); }
}else{
response.sendRedirect("Login.jsp");
} }}
ExitServlet.javapackage 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");
}
}问题
只要ExitServlet改成doGet才能不报错 如果是doPost()就会出现
HTTP method GET is not supported by this URL求指点
另:jsp和servlet的标准api在哪看
a标签发送的url字符串链接,就是get请求。。
如果楼主实在想用doPost方法,
就在doGet方法中加一句
this.doPost(request, response);
就可以了。