分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

JSP数据交互(一)

发布时间:2023-09-06 01:51责任编辑:董明明关键词:暂无标签

1.JSP内置对象

请求对象:request

输出对象:out

响应对象:response

应用程序对象:application

会话对象:session

页面上下文对象:pageContext

页面对象:page

配置对象:config

异常对象:exception

2.request对象的常用方法:

String  getParameter(String  name):根据页面表单组件名称获取页面提交数据

String [ ]   getParamterValues(String name):获取一组以相同   名称命名的表单组件 提交的数据

 void setCharacterEncoding(String charset):  指定每个请求的编码,在调用request.getParameter()方法之前进行设定,可以用于解决中文乱码问题  

 RequestDispatcher getRequestDispatcher(String payh):返回一个javax.servlet.RequestDispacher对象,该对象的foeward()

 

index:

<%@ 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=UTF-8"><title>Insert title here</title></head><body> ???<% ???????String username = request.getParameter("username"); ???????String password = request.getParameter("password"); ???????if (username.equals("lps") && password.equals("lucky")) { ???????????response.sendRedirect("welcome.jsp"); ???????} else { ???????????out.println("请检查用户名和密码是否正确!"); ???????} ???%></body></html>

controller:

<%@ 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=UTF-8"><title>Insert title here</title></head><body> ???<form action="controller.jsp" method="post"> ???????<table> ???????????<tr> ???????????????<td>用户名</td> ???????????????<td><input type="text" name="username"></td> ???????????</tr> ???????????<tr> ???????????????<td>密码</td> ???????????????<td><input type="password" name="password"></td> ???????????</tr> ???????????<tr> ???????????????<td colspan="2"><input type="submit" value="登录"></td> ???????????</tr> ???????</table> ???</form></body></html>

welcome:

<%@ 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=UTF-8"><title>Insert title here</title></head><body> ???<h1>欢迎您,来到贵美!</h1></body></html>

方法用于转发请求  

 

JSP数据交互(一)

原文地址:https://www.cnblogs.com/864466244qq/p/8946708.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved