今天照着参考书做一个jsp登陆页面的练习,页面成功显示,但是我点击按钮不会登陆
代码我是照着书打上去的 大家帮我看一下吧
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<FROM id=vForm action='LoginC1' name=vForm method=post>
<DIV class=logoicon></DIV>
<DIV class=main_top>
<DIV class="title_note1 red link" id=login_err></DIV>
</DIV>
<DIV class=main_cen>
<p class=title>登陆</p>
<UL class=mainlogin>
<LI>
<DIV class="m1_1 f14">登陆名:</DIV>
<div class=ml_r>
<div class=inputbox><SPAN class=input><cite><input id=username tabIndex=0
alt=会员名:无内容/长度{4-64}/errArea{usernameErr} maxLength=64 name= username
autocomplete="off"></cite></SPAN></div><SPAN class="inputacc link"></SPAN>
<SPAN class="red link" id=usernameErr></SPAN></div>
<li>
<div class="ml_l f14">密码:</div>
<div class=ml_r>
<div class=inputbox><span class=input><cite><input id=password tabIndex=1 type=password maxLength=32 name=passwd>
</cite></span> </div><span class="inputacc link"><a>找回密码</a></span><span class="red link" id=passwordErr></span></div>
<li>
<div class=ml_l></div>
<div class=ml_r>
<div class=inputacc><LABEL for=savestate><INPUT id=savestate
onclick="document.getElementById('savestate_tip').style.display = this.checked?'block':'none';"
tabIndex=3 type=checkbox name=savestate> 记住登陆状态</LABEL></div>
<div class="inputtxt zi_9" id=savestate_tip
style="DISPLAY: none">建议在网吧/公用电脑上取消该选项</div></div>
<li>
<div class=ml_l></div>
<div class=ml_r><INPUT class=btn_submit tabIndex=4 type=submit value="登陆">
</div>
<div class=clearit></div>
</LI>
</UL>
</DIV>
<div class=main_bottom></div>
</FROM>
名字叫LoginC1的servlet
package com.helloworld;
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;
public class LoginC1 extends HttpServlet {
/**
* Constructor of the object.
*/
public LoginC1() {
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)
{
try
{
//中文乱码情况
response.setContentType("text/html; charset=gbk");
//接受用户和密码
String u=request.getParameter("username");
System.out.println(u);
String p=request.getParameter("passwd");
//验证
if(u.equals("root")&&p.equals("root"))
{
//合法
response.sendRedirect("Welcome");
}
else
{
response.sendRedirect("erro");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
/**
* 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)
{
this.doGet(request,response);
}
/**
* Initialization of the servlet. <br>