2013年12月17日星期二

tomcat can not jump , seeking Great God help

Login screen login, authentication processing class logincl, welcome screen welcome, the configuration xml
In tomcat can not complete the verification Great God help hope


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>

------ Solution ------------------------------------- -------
breakpoint debugging is not already accessible to the user name and password ?
------ Solution ---------------------------------------- ----
  The reply was deleted administrator at 2013-12-17 08:46:52

------ Solution ------------------------------------ --------
 if (u.equals("txj") && p.equals("123")) {
            // 合法E
            // res.sendRedirect("welcome");//你要的servlet的url
            res.sendRedirect("welcome1");
        } else {
            // 不合法,跳转
            res.sendRedirect("login1");// 你要的servlet的url
        }


Here is welcom1 and login1
your web.xml inside it than simply the corresponding url-pattern, the landlord to check the configuration files , java class jumps and configuration files do not match
------ Solution --- -----------------------------------------
pw.println ("
");
changed
pw.println (""); you try.
------ Solution ---------------------------------------- ----
eyes ; did not notice the capitalization errors
------ Solution ----------------------------- ---------------
change according to the fifth floor of the operation , this error is the next error , can not jump is currently the fifth floor to point out that the problem
--- --- For reference only ---------------------------------------
if (u.equals ("txj") && p.equals ("123")) I would simply direct match

logiincl not work
do not know why
------ For reference only ------------------------------- --------
I configure welcom1 and login1 is just wrong

 if (u.equals("txj") && p.equals("123")) {
// 合法E 
res.sendRedirect("welcome");       
 } else {             // 不合法,跳转          
   res.sendRedirect("login");// 你要的servlet的url 
}


this does not work , I tried ,
------ For reference only -------------------------- -------------

Thank You
After correction , the results came out !
------ For reference only --------------------------- ------------
thank the great God who !!!

没有评论:

发表评论