日期:2014-05-17  浏览次数:20680 次

求大牛,简单的form传值给servlet
JSP代码:
---------
<%@ page language="java" contentType="text/html; charset=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>SYSTEM</title>
</head>
<body>
<br><br><br><br>
<form action="LoginServlet" method="post" name="form">
<hr>
<center><img align="middle" width="230" height="40" src="image/111.jpg"/></center>
<p align='center' >Welcome to XXXXX Co., Ltd.        <p>
<p align='center' >Since 2010<p>
<hr>
<table align="center" >
<tr>
<td style="font-size: 15px" >客户经理号:</td>
<td><input name="khjl" type="text" value="" id="khjl"></td>
<td style="font-size: 15px" >密码:</td>
<td><input name="password" type="password" value="" id="password"></td>
<td align="center" style="font-size: 15px"><input type="submit" name="Submit" value="LOGIN"></td>
</table>
<hr>
</form>
</body>
</html>








servlet代码:
----------
package com.Login;
import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet 
{
//doGet
protected void doGet
( HttpServletRequest 
request,
HttpServletResponse 
response){
}

//doPost
protected void doPost
( HttpServletRequest 
request,
HttpServletResponse 
response)
throws ServletException,IOException
{
request.setCharacterEncoding("utf-8");
//String khjl=request.getParameter("khjl");
String password=request.getParameter("password");
 
System.out.println(password);

if(1>0)
{
System.out.println("123");

}
}
private static final long serialVersionUID = 1L;
}


web.xml:
----------
        <servlet>
<servlet-name>
LoginServlet
</servlet-name>
<servlet-class>
com.Login.LoginServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>




servlet取得参数值为NULL

------解决方案--------------------
吧<input name="password" type="password" value="" id="password">里面的value=""删掉试试