zoukankan      html  css  js  c++  java
  • jsp 中的getParameter和getAttribute

    从页面传到后台action中的参数可以用三种方式接收:

    1.声明一个变量,然后设置其getter和set方法

    private String username;

     public String getUsername() {
      return username;
     }
     public void setUsername(String username) {
      this.username = username;
     }

    2.通过getParameter

    request.getParameter("username");

    3,通过getAttribute

    request.getAttribute("username");

    在jsp页面中的通过request.setAttribute("pwd","123456");设置的参数,在后台用上述三种方法都取不到值。

    在后台action中通过request.setAttribute("pwd","123456");设置的参数,在jsp页面中可以用request.getAttribute("pwd");获得。

    在jsp页面中:可以通过${person }获得action中通过ServletActionContext.getRequest().setAttribute("person", person);设置的值。

    通过?方式传给action的参数比如:http://localhost:8080/hello/act1.action?fileName=jquery.chm,在页面中通过${param.fileName}获得其值;如果action中有fileName的setter和getter方法,则还可以通过${fileName}的方式获得。

  • 相关阅读:
    组合模式
    迭代器模式
    模板方法模式
    外观模式
    适配器模式
    运行mysql时,提示Table ‘performance_schema.session_variables’ doesn’t exist
    idea maven 打包 引用本地jar
    centos7 安装redis
    centos7 防火墙
    linux 常用命令
  • 原文地址:https://www.cnblogs.com/passer1991/p/2967058.html
Copyright © 2011-2022 走看看