首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

tomcat不能跳转,求大神帮忙解决方法

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

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 ServletException, IOException {
// 中文乱码
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, IOException {
PrintWriter pw = res.getWriter();
pw.println("Welcome to my home !!!");
}

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




<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1"
  metadata-complete="true">



  <display-name>Tomcat Manager Application</display-name>
  <description>
    A scriptable management web application for the Tomcat Web Server;
    Manager lets you view, load/unload/etc particular web applications.
  </description>

  <servlet>
  <!--give servlet name        1 -->
    <servlet-name>login</servlet-name>
<!--servlet track,(bao name and class name)-->
    <servlet-class>com.txj.servlet.demo.Login</servlet-class>
  </servlet>

  <!-- Define the Manager Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>login</servlet-name>
<!--on browser ,intput servlet's url-->
      <url-pattern>/login</url-pattern>
  </servlet-mapping>

<servlet>
  <!--give servlet name        2 -->
    <servlet-name>logincl</servlet-name>
<!--servlet track,(bao name and class name)-->
    <servlet-class>com.txj.servlet.demo.LoginCL</servlet-class>
  </servlet>

  <!-- Define the Manager Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>logincl</servlet-name>
<!--on browser ,intput servlet's url-->
      <url-pattern>/logincl</url-pattern>
  </servlet-mapping>

  <servlet>
  <!--give servlet name        3 -->
    <servlet-name>welcome</servlet-name>
<!--servlet track,(bao name and class name)-->
    <servlet-class>com.txj.servlet.demo.Welcome</servlet-class>
  </servlet>

  <!-- Define the Manager Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>welcome</servlet-name>
<!--on browser ,intput servlet's url-->
      <url-pattern>/welcome</url-pattern>
  </servlet-mapping>
</web-app>

 火眼金睛 都没注意到那个大小写错误 
[解决办法]
引用:
我配置welcom1 和 login1是刚才打错了

 if (u.equals("txj") && p.equals("123")) {
// 合法E 
res.sendRedirect("welcome");       


 } else {             // 不合法,跳转          
   res.sendRedirect("login");// 你要的servlet的url 
}



这样不行,我试过了,
按五楼操作改,这个错误是下一个错误,当前不能跳转是5楼指出的那个问题 

热点排行