下载此文档

jsp课件- Servlet通信方法和上下文状态.ppt


文档分类:IT计算机 | 页数:约19页 举报非法文档有奖
1/19
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/19 下载此文档
文档列表 文档介绍
专题二 Servlet技术
案例三 Servlet通信方法和上下文状态
教学目标
熟悉Servlet的通信方法
掌握Servlet的上下文接口
工作任务
使用Post方法传递数据实现用户登录功能
新建工程、包和登录页面
1. 新建“loginIn”工程
2. .”包
3.
<form action="login" method="post">
用户名:<input type="text" name="loginname"/>
密&nbsp;&nbsp;码:
<input type="password" name="loginpwd"/>
<input type="submit" value="登录"/>
</form>


在<BODY></BODY>标签中间加入内容,整体代码如下:
<head>
<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">
</head>
<body>
登录成功--欢迎光临
</body>

5.
<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">

<body>
登录失败---用户名或密码错误<br/>
<a href="" target="_self">请重新登录</a>
</body>

导入需要的类
继承HttpServlet
编写doGet()方法
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}

6. ,()方法代码如下:
String username=("loginname");
String loginname=
getServletContext().getInitParameter("loginname");
if((username)){
getServletContext().getRequestDispatcher("/").
forward(request, response);
}else{
("");
}
配置Servlet
7.
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<context-param>
<pa

jsp课件- Servlet通信方法和上下文状态 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数19
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xxj16588
  • 文件大小300 KB
  • 时间2018-01-10