《JSP》<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
 <form action="login " name="form1" method="post" >
 <center>
 
  用户名: <input type="text" name="username">
  <input type="submit" value="OK">
 
 </center>  </form>
</body>
</html><servlet中>
package login;
import javax.servlet.*;
import java.io.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.*;/**
 * Servlet implementation class login
 */
public class login extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public login() {
        super();
        // TODO Auto-generated constructor stub
    } /**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub


System.out.print("ffff");
response.sendRedirect("index.jsp");
} /**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request,response);
}}为什么 我提交后,不去 我的servlet的doGet里面!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    你的路径对吗,检查下server映射路径
      

  2.   

    大哥你是用表单提交的。
    并且form中还用的是method="post"
    = =!
      

  3.   

    <form action="login " name="form1" method="post" >
    你这个action的地址是你那个servlet的地址吗?你的web.xml怎么配的
      

  4.   

    你把你的web.xml粘出来,看下路径是否和action中的login是否一致。
      

  5.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" 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">
    <display-name>
    log</display-name>
    <servlet>
    <description>
    </description>
    <display-name>
    login</display-name>
    <servlet-name>login</servlet-name>
    <servlet-class>
    login.login</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login</url-pattern>
    </servlet-mapping>
    <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>
    </web-app>
      

  6.   

    你的wen.xml是怎么写的?
    进doPost了吗?
      

  7.   

     我认为是你的servlet 生命周期不全,有doGet()方法,但少了init()和destory().这样是无法加载文件的。还有jsp中用的是post方法,这个容易出错。
      

  8.   

    地址错误  action = "/login"
      

  9.   

    检查两个地方就好了,一个是web.xml里的映射,一个是你的servlet的写法,最好是把doGet()里也用doPost()处理.
      

  10.   

    <form action="login " name="form1" method="post" > 这里面="login "不能空着吧!是不是写成这样呢!  ="login"
      

  11.   

    9楼下解。。写程序要细心。。特别是j2ee的。
      

  12.   

    路径没错啊,程序也没错,有没有报错啊,假如没报错的话就是你的url打错了
      

  13.   

    /login  web.xml中配置是对的吗??