zhuhb1234
zhuhb1234
2016-08-04 08:58

各位,在线等 servlet跳不进!!!!!

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>test2.5</display-name>
    <!-- <listener>
        <listener-class>javax.servlet.ServletContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>javax.servlet.http.HttpSessionListener</listener-class>
    </listener> -->
    <!-- <filter>
        <filter-name>encodingfilter</filter-name>
        <filter-class>com.hr.test.filter.EncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingfilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>-->

    <servlet>
        <servlet-name>loginServlet</servlet-name>
        <servlet-class>com.hr.test.servlet.LoginServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>loginServlet</servlet-name>
        <url-pattern>/LoginServlet</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

servlet

 package com.hr.test.servlet;

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 LoginServlet extends HttpServlet {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public void init() throws ServletException {
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response){

        String name = (String) request.getParameter("name");
        String pwd = (String) request.getParameter("pwd");

        if (name.equals("1234") && pwd.equals("123")) {
            response.setContentType("text/html");
            PrintWriter out=null;
            try {
                out = response.getWriter();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            out.print("登陆成功!!!");
        }
    }

    @Override
    public void destroy() {
        // TODO Auto-generated method stub
    }
}

index.jsp

 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>

<body>
    <form action="http://localhost:8080/loginServlet" method="post">
        <table>
            <tr>
                <th>用户名</th>
                <th><input name="name"/></th>
            </tr>
            <tr>
                <th>密码</th>
                <th><input name="pwd"/></th>
            </tr>
            <tr>
                <th rowspan="1"></th>
                <th><input value="登陆" type="submit"/></th>
            </tr>
        </table>
    </form>
</body>
</html>

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐

换一换