jsp入门学习2


<% response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
%>

<%response.setHeader("refresh", "10"); %>

<%response.setHeader("refresh", "5;url=delete.jsp"); %>

==========================================

index.jsp

<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




显示时间
















  • ===============================================================

    reg.jsp

    <%@page import="org.apache.catalina.filters.SetCharacterEncodingFilter"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>






    javaBean 获得对象的属性值


    <%request.setCharacterEncoding("UTF-8"); %>



















    姓名:
    性别:
    年龄:
    地址:



    =============================================================

    deal.jsp

    <%@page import="java.util.Date"%>
    <%@page import="javax.xml.crypto.Data"%>
    <%@page import="java.net.URLEncoder"%>
    <%@page import="java.net.URLDecoder"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>




    写入cookie


    <%
    request.setCharacterEncoding("UTF-8");
    String user = URLEncoder.encode(request.getParameter("user"),"utf-8");
    Cookie cookie = new Cookie("myCookie", "user" + "#" + new Date().toLocaleString());
    cookie.setMaxAge(60*60*24*30);
    response.addCookie(cookie);

    %>



    =================================================

    三个Bean对象

    package com.ljl.bean;


    import java.awt.image.SampleModel;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;


    public class DateBean {
    private String date;
    private String week;

    private Calendar calendar = Calendar.getInstance();


    public String getDate() {
    Date curDate = Calendar.getInstance().getTime();
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日  HH时mm分ss秒");
    date = format.format(curDate);
    return date;
    }


    public void setDate(String date) {
    this.date = date;
    }


    public String getWeek() {
    String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
    int index = calendar.get(Calendar.DAY_OF_WEEK);
    week = weeks[index-1];
    return week;
    }


    public void setWeek(String week) {
    this.week = week;
    }


    }

    ===============================================

    package com.ljl.bean;


    public class Persion {
    private String name;
    private int age;
    private String sex;
    private String addr;

    public Persion() {
    // TODO Auto-generated constructor stub
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    public String getSex() {
    return sex;
    }
    public void setSex(String sex) {
    this.sex = sex;
    }
    public String getAddr() {
    return addr;
    }
    public void setAddr(String addr) {
    this.addr = addr;
    }


    }

    =============================================

    package com.ljl.bean;


    public class Produce {
    private String name = "广州房子";
    private double price = 35635678.343;
    private int count = 100;
    private String address = "广东省广州市天河区龙口东路";
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public double getPrice() {
    return price;
    }
    public void setPrice(double price) {
    this.price = price;
    }
    public int getCount() {
    return count;
    }
    public void setCount(int count) {
    this.count = count;
    }
    public String getAddress() {
    return address;
    }
    public void setAddress(String address) {
    this.address = address;
    }
    }

    你可能感兴趣的:(JSP)