码迷,mamicode.com
首页 > 其他好文 > 详细

Servlet编程实例-servlet学习之旅(三)

时间:2015-05-11 17:56:56      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:servlet   j2ee   

技术分享

LoginServlet代码:

public class LoginServlet extends HttpServlet{

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String name = req.getParameter("uName");
        String pswd = req.getParameter("uPswd");
        System.out.println("用户名:"+name);
        System.out.println("密码:"+pswd);
    }

}

Login.jsp的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>登陆界面</title>
</head>
<body>
    <form action="<%= request.getContextPath() %>/loginServlet" method="get">
        userName:<input type="text" name="uname" /><br/>
        userPwsd:<input type="password" name="upwsd" /><br/>
        <input type="submit" value="Login"/>
        <input type="reset" value="Reset"/>
    </form>
</body>
</html>

配置文件

 <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>liu.peng.servlet.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/loginServlet</url-pattern>
  </servlet-mapping>

效果图:
技术分享

Servlet编程实例-servlet学习之旅(三)

标签:servlet   j2ee   

原文地址:http://blog.csdn.net/lpjishu/article/details/45645959

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!