tomcat不能跳转,求大神帮忙
登录界面login,验证处理类logincl,欢迎界面welcome,配置xml了
在tomcat中不能完成验证
希望大神帮忙
在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>
...全文
相关推荐
Tomcat配置https并访问http自动跳转至https
Apache Tomcat是一个广泛使用的开源Web服务器和Servlet容器,下面将详细介绍如何在Tomcat中配置HTTPS,并实现当用户通过HTTP协议访问时,自动跳转到HTTPS协议。
Tomcat自动https跳转配置
"Tomcat自动https跳转配置"在互联网安全日益重要的今天,HTTPS协议因其数据加密传输特性成为了网站必备的安全标准。本篇文章主要探讨如何在Tomcat服务器上配置自动从HTTP到HTTP
Spring Boot项目导出war包放到tomcat运行跳转到页面出现404报错
然而,在这一过程中可能会遇到各种问题,比如跳转页面时出现404错误,即服务器无法找到指定资源。本文将围绕这一问题进行深入探讨,并提供相应的解决方案。
spring mvc+maven+tomcat+浏览器服务请求,页面跳转
基于IntelliJ IDEA,spring mvc,maven,tomcat,实现了web下,用三种方式来访问某个页面,以及页面之间的跳转
windows环境下nginx的入门配置跳转tomcat-附件资源
windows环境下nginx的入门配置跳转tomcat-附件资源


Web 开发
