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

tomcat不能跳转,求大神帮忙
登录界面login,验证处理类logincl,欢迎界面welcome,配置xml了
在tomcat中不能完成验证
希望大神帮忙

package com.txj.servlet.demo;

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 Login extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletExceptionIOException {
// 中文乱码
res.setContentType("text/html;charset=gbk");
PrintWriter pw = res.getWriter();
pw.println("<html>");
pw.println("<body>");
pw.println("<h1>登录界面</h1>");
pw.println("<form action=LoginCL method='post'>");
pw.println("用户名:<input type=text name=username><br>");
pw.println("密码:<input type=password name=passwd><br>");
pw.println("<input type=submit value=login><br>");
pw.println("</form>");
pw.println("</body>");
pw.println("</html>");
}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
this.doGet(req, res);
}
}


package com.txj.servlet.demo;

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 LoginCL extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// 接收用户名和密码
String u = req.getParameter("username").trim();
String p = req.getParameter("passwd").trim();
// 验证
if (u.equals("txj") && p.equals("123")) {
// 合法E
// res.sendRedirect("welcome");//你要的servlet的url
res.sendRedirect("welcome1");
} else {
// 不合法,跳转
res.sendRedirect("login1");// 你要的servlet的url
}
}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

this.doGet(req, res);
}
}



package com.txj.servlet.demo;

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 Welcome extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,&nb