为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
JAVA遇见HTML——JSP篇_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

JAVA遇见HTML——JSP篇

milanlover JAVA开发工程师
难度入门
时长 7小时 0分
  • html中点击链接不进行跳转的方法: 1:<a href="####"></a> 2:<a href="javascript:void(0)"></a> 3:<a href="javascript:void(null)"></a> 4:<a href="#" onclick="return false"></a> 5:<span ></span>(好像在FF中不能显示) 1.在服务器中,属性是以String传递的,如果定义为其他类型,则在使用时需要强制转换: (1)Integer.parseInt(得到的值), (2)在值前面加类名
    查看全部
  • 1,连接数据库的架包放在WEB-INF的lib文件夹下<br><br> 2,数据库驱动,数据库连接字符串,用户名,密码,这些设置为私有的,静态常量,没必要也不允许在后面的代码中进行修改<br> 3,设置数据库的编码字符集useUnicode=true&characterEncoding=UTF-8 JDBC连接MySql<br> 1、在lib中添加jar包 2、DBhelper类 public class DBHelper{ private static final Sring driver="com.mysql.jdbc.Driver";//数据库驱动 private static finalString url="jdbc:mysql://localhost:3306/shopping?useUnicon=true&characterEncoding=UTF-8"//连接地址 private static finalString username = "root";//数据库用户名 private static finalString password = "";//数据库密码 private static Connection conn = null; //静态代码块负责加载驱动 static{ try{ Class.forName(driver); } catch(Exception ex){ ex.printStackTrace(); } } //单例模式返回数据库连接对象 public static Connection getConnection() throws Exception{ if(conn==null){ Connection con=DriverManager.getConnection(url,username,password); return conn; } return conn; } }
    查看全部
    0 采集 收起 来源:DBHelper类设计

    2018-03-22

  • <jsp:include>动作在请求期间被执行,而include指令在编译期页面间被执行 页面内容经常变化时更适合使用<jsp:include>动作 页面内容不经常变化时更适合使用include指令 <jsp:include>动作包含的是执行结果,而include指令包含的是文件内容
    查看全部
    0 采集 收起 来源:练习题

    2018-03-22

  • 1,param动作用法:<jsp:param name="参数名" value="参数值"> 一般和forward动作连用,作为forward的子标签进行使用 2,向另一个页面传递参数 可以传递新的参数+可以修改原有的参数 <jsp:forward page="user.jsp"> <jsp:param name="email" value="110@qq.com"> <jsp:param name="password" value="111"> </jsp:forward> @login.jsp <form action="dologin.jsp" method="post">...</form> @dologin.jsp <jsp:forward page="user.jsp" > <jsp:param value="8888" name="password"/>//name要与login.jsp的一致 </jsp:forward> @user.jsp //同上章
    查看全部
    0 采集 收起 来源:param动作

    2018-03-22

  • forward动作: <jsp:forward page="url"/> 这个指令等同于request.getRequestDispatcher().forward(request,response);
    查看全部
    0 采集 收起 来源:forward动作

    2018-03-22

  • include指令和include动作的比较 语法格式 <%@ include file="url" %> <jsp:include page="url"> 发生作用期间 页面转换期间 请求期间 包含内容 文件的实际内容 页面的输出 转换成的servlet 主页面和包含页面转换为一个servlet 主页面和包含页面转换为独立的servlet 编译时间 较慢 资源必须被解析 较快 执行时间 稍快 较慢 每次资源必须被解析 inlude指令与include动作的区别: include指令是编译阶段的指令,是将主页面和包含页面转换成一个servlet,因此编译较慢,执行较快。 include动作在编译阶段是将主页面和包含页面编译成俩个servlet,在执行期间调用页面输出。因此编译较快,执行较慢。 因此include指令用于不经常变化的内容,难以维护;include动作方便维护
    查看全部
  • nclude动作: <jsp:include page="url" flush="false"/> include指令: <%@include file="url" %> include动作(动作标签) <jsp:include page="URL" flush="true/false" /> page 要包含的页面 flush 被包含的页面是否从缓冲区读取 include嵌入指令三个常用的动作:<jsp:forward>\<jsp:param>\<jsp:plugin> include指令语法:<%@ include file = "URL;要提出的文件夹"%> include动作标签语法:<jsp:include page="URL要包含的页面" flush="true|false"/>
    查看全部
    0 采集 收起 来源:include动作

    2018-03-22

  • <%@include file="url" %> 注:使用include标签,要删掉jsp页面生成的html无用的代码,否则会报错 定义时间类: Date xx=new Date(); simpleDateFormat XX=new simpleDateFormat("yyyy-MM-dd"); String XXX=XX.format(xx); 一、basePath的用法:<br> 1,<% <br> String path=request.getContextPath();<br> String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";<br> %><br> 2,利用html中的 <base>标签(该标签放到<head>标签中)<br> <base href="<%=basePath%>"> 二、base标签的作用 可规定页面中所有链接的基准 URL JSP指令与动作-->指令有page、include、taglib。动作有<jsp:forward>,<jsp:param>,<jsp:plugin>三个动作 指令格式:<% @ include file="date.jsp"%> @Include_Command.jsp <%@ include file="test.jsp" %>//注意:被包含的页面一些代码需要删除,否则重复 @test.jsp <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% out.println("测试页面"); %> 常用的有page、include、taglib指令这三种指令; page:位于页面顶端,一个页面可以包含多个page指令 include:将一个外部文件嵌入jsp中,同时解析这个页面中的jsp语句。 taglib:使用标签库,自定义新的标签,在jsp中启动定制行为。
    查看全部
    0 采集 收起 来源:include指令

    2018-03-22

  • 设置当前Cookie的生存期限为24小时setMaxAge(86400);setMaxAge() 参数是毫秒
    查看全部
    0 采集 收起 来源:练习题

    2016-06-10

  • Cookie是客户端保存用户状态的机制 Session是服务器端保存用户状态的机制 Cookie与Session都可以设置生存期限 Cookie中对保存对象的大小是有限制的
    查看全部
    0 采集 收起 来源:练习题

    2016-06-10

  • Session与Cookie的对比: 1、Session保存在服务器端,Cookie保存在客户端; 2、Session保存的是Object类型,Cookie保存的是String类型; 3、Session随会话的结束将其存储的数据销毁,Cookie可以长期保存在客户端; 4、Session保存重要信息,Cookie保存不重要信息;
    查看全部
  • @dologin.jsp——(下) else { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie c : cookies) { //addCookie()时,已经把user和pwd存进去 if (c.getName().equals("user") || c.getName().equals("pwd")) { c.setMaxAge(0);//设置Cookie失效 response.addCookie(c);//一定要重新保存,否则失效 } } } } %> <a href="users.jsp" target="_blank">查看用户信息</a> @login.jsp <% String user = ""; String pwd = ""; Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie c : cookies) { if (c.getName().equals("user")) { user = URLDecoder.decode(c.getValue(),"utf-8"); } if (c.getName().equals("pwd")) { pwd = 同上; } } } %> <input type="text" value="<%=user %>" name="username"/> <input type="password" value="<%=pwd %>" name="password"/> <input type="checkbox" checked="checked" name="isUseCookie" value="sun"/>7天内记住我的登录状态
    查看全部
  • @dologin.jsp——(上) <h1> 登录成功 </h1> <hr> <br> <% request.setCharacterEncoding("utf-8"); //首先判断用户是否选择了记住登录状态 String[] isUseCookies = request.getParameterValues("isUseCookie"); //只有checkbox勾选了,value起作用 if (isUseCookies != null && isUseCookies.length > 0) { //把用户名和密码保存在Cookie对象里面 String user = URLEncoder.encode(request.getParameter("username"), "utf-8"); //使用URLEncoder解决无法在Cookie当中保存中文字符串的问题(引入java.net.*) String pwd = URLEncoder.encode(request.getParameter("password"), "utf-8"); Cookie userCookie = new Cookie("user", user); Cookie pwdCookie = new Cookie("pwd", pwd); userCookie.setMaxAge(86400);//设置最大生存期限为10天 pwdCookie.setMaxAge(86400); response.addCookie(userCookie); response.addCookie(pwdCookie); }
    查看全部
  • @users.jsp <h1> 用户信息 </h1> <% request.setCharacterEncoding("utf-8"); String user = ""; String pwd = ""; Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie c : cookies) { if (c.getName().equals("user")) { user = URLDecoder.decode(c.getValue(),"utf-8"); } if (c.getName().equals("pwd")) { pwd = URLDecoder.decode(c.getValue(),"utf-8"); } } } %> <hr> <br> <br> <br> 用户名:<%=user %> <br> 密码:<%=pwd %> @request.getParameterValues与request.getParameter的区别 request.getParameterValues(String name)是获得如checkbox类(名字相同,但值有多个)的数据。接收数组变量 ,如:checkobx类型(如果不写value的值,默认为“on”) 。 request.getParameter(String name)是获得相应名的数据,如果有重复的名,则返回第一个的值。接收一般变量 ,如:text类型。 Ps1:value="<%=user %>":记住引号要加上去。 Ps2: addCookie();//使用——>URLEncoder.encode(); c.getValue();//使用——>URLDecoder.decode();
    查看全部
  • 一、 简单的对比 request.getParameter用的比较多,相对熟悉 request.getParameterValues(String name)是获得如checkbox类(名字相同,但值有多个)的数据。 接收数组变量 ,如checkobx类型 request.getParameter(String name)是获得相应名的数据,如果有重复的名,则返回第一个的值 . 接收一般变量 ,如text类型 例: 1. 三个名字相同的text标签 <input type="text" name="test" value="1" /> <input type="text" name="test" value="2" /> <input type="text" name="test" value="3" /> request.getParameterValues("test") ----------------- [1, 2, 3] request.getParameter("test") ------------------ 1 (1)每个网站只能读取自己创建的cookie,cookie在每次http请求时,会被携带在请求中发送到服务器。 (2)request.getParameterValues(String name),获取的是名字相同,但是value值不同的多个表单域的值,会自动排列为字符串对象数组。 (3)Cookie中的编码和解码问题: a.导入Java网络包中的一个编码与解码类,对象是URLDecoder和URLEncoder b.在login.jsp中也写,就是在下次response对象返回时拿回的cookie存放在本地客户端里。 解决cookie中无法保存中文的问题: request.setCharacterEncoding("utf-8") URLEncoder.encode()编码 URLDecoder.decode()解码
    查看全部

举报

0/150
提交
取消
课程须知
Hi,我是JSP。为了让您更好的了解我,请先学习我的小伙伴JAVA和HTML。
老师告诉你能学到什么?
学完JSP,您可以掌握JSP基本语法,理解Java Web开发思想,进而能独立开发简单的Java Web应用。
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!