web一些实验代码—— JavaBean与EL标签

 实验9: JavaBean与EL标签

使用javaBean和EL,完成注册和注册信息显示。

1、新建RegisterBean;

package com.example.weeebbbb.the10;

public class RegisterBean {
    private String user;
    private String pass;
    private String repass;
    private String realname;
    private String gender;
    private String[] chanel;

    public RegisterBean() {
    }

    public String getRepass() {
        return repass;
    }

    public void setRepass(String repass) {
        this.repass = repass;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String[] getChanel() {
        return chanel;
    }

    public void setChanel(String[] chanel) {
        this.chanel = chanel;
    }
}

2、新建register.jsp,实现注册功能;

<%--
  Created by IntelliJ IDEA.
  User: cic
  Date: 2023/11/8
  Time: 10:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


用户名:
密码:
真实姓名:
性别:
你从哪里知道本网站的主题:
网站 报纸 电视

web一些实验代码—— JavaBean与EL标签_第1张图片

更换

里的action,选择不同的方法去实现信息显示

3、新建info.jsp,使用javaBean和EL实现注册信息显示。

(1)使用基本方法实现信息显示:
<%--
  Created by IntelliJ IDEA.
  User: cic
  Date: 2023/11/8
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


<%
    response.setContentType("text/html;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");
    String user=request.getParameter("user");
    String pass=request.getParameter("pass");
    String gender=request.getParameter("gender");
    String realname=request.getParameter("realname");
    String chanel[]=request.getParameterValues("chanel");
    String newChanel="";
    for (int i=0;i

用户提交信息

用户名密码真实姓名性别渠道
<%=user%><%=pass%><%=realname%><%=gender%><%=newChanel%>

web一些实验代码—— JavaBean与EL标签_第2张图片


(2)使用实现;
<%@ page import="com.example.weeebbbb.the10.RegisterBean" %><%--
  Created by IntelliJ IDEA.
  User: cic
  Date: 2023/11/8
  Time: 10:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%request.setCharacterEncoding("UTF-8");%>


    Title



    


用户名:
密码:
确认密码:
姓名:
性别:
你从哪里知道这个网站的: <% request.setCharacterEncoding("UTF-8"); RegisterBean rb=(RegisterBean) request.getAttribute("stu"); String[] chanel=rb.getChanel(); String str=""; for (int i=0;i< chanel.length;i++){ str=str+ chanel[i]+" "; } %> <%=str%> <%--<%=stu.getChanel()%>--%>

web一些实验代码—— JavaBean与EL标签_第3张图片


(3)使用EL标签实现。
<%@ page import="com.example.weeebbbb.the10.RegisterBean" %><%--
  Created by IntelliJ IDEA.
  User: cic
  Date: 2023/11/8
  Time: 10:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%request.setCharacterEncoding("UTF-8");%>


    Title


学生信息显示


用户名:${stu.user} 密码:${stu.pass} 姓名:${stu.realname} 性别:${stu.gender} 信息来源渠道: <% // request.setCharacterEncoding("UTF-8"); RegisterBean rb=(RegisterBean) request.getAttribute("stu"); String[] chanel=rb.getChanel(); String str=""; for (int i=0;i< chanel.length;i++){ str=str+ chanel[i]+" "; } request.setAttribute("str",str); %> ${str}

web一些实验代码—— JavaBean与EL标签_第4张图片

你可能感兴趣的:(前端,java,servlet)