JSP userBean setProperty直接从request中获取参数

JSP userBean setProperty直接从request中获取参数:

form表单Jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="true"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>008index</title>
</head>
<body>
    <form action="index015.jsp" method="post">
        <input type="text" name="userName">
        <input type="submit" value="submitUserName">
    </form>
    <form action="index015.jsp" method="post">
        <input type="text" name="name">
        <input type="submit" value="submitName">
    </form>
    <form action="index015.jsp" method="post">
        <input type="text" name="name">
        <input type="text" name="age">
        <input type="submit" value="submitNameAge">
    </form>
</body>
</html>

获取表单参数JSP:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="true"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>008index</title>
</head>
<body>
    <p>
        <jsp:useBean id="person" class="com.stono.servlet.bean.Person">
            <jsp:setProperty name="person" property="name" param="userName1"></jsp:setProperty>
        </jsp:useBean>
        Name is <jsp:getProperty property="name" name="person"/>
        <pre>
            此处生成的servlet java文件为:
            org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person"), "name", request.getParameter("userName1"), request, "userName1", false);
        </pre>
    </p>
    <p>
        <jsp:useBean id="person2" class="com.stono.servlet.bean.Person">
            <jsp:setProperty name="person2" property="name" ></jsp:setProperty>
        </jsp:useBean>
        Name is <jsp:getProperty property="name" name="person2"/>
        <pre>
            此处生成的servlet java文件为:
            org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person2"), "name", request.getParameter("name"), request, "name", false);
        </pre>
    </p>
    <p>
        <jsp:useBean id="person3" class="com.stono.servlet.bean.Person">
            <jsp:setProperty name="person3" property="*" ></jsp:setProperty>
        </jsp:useBean>
        Name is <jsp:getProperty property="name" name="person3"/>
        Age is <jsp:getProperty property="age" name="person3"/>
        <pre>
            此处生成的servlet java文件为:
            org.apache.jasper.runtime.JspRuntimeLibrary.introspect(_jspx_page_context.findAttribute("person3"), request);
       </pre>
    </p>

</body>
</html>

获取表单参数JSP的servlet:

/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.35
 * Generated at: 2015-10-26 00:15:33 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;

public final class index015_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                  null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");

    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

      out.write("\r\n");
      out.write("<!DOCTYPE html>\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("<meta charset=\"UTF-8\">\r\n");
      out.write("<title>008index</title>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("\t<p>\r\n");
      out.write("\t\t");
      com.stono.servlet.bean.Person person = null;
      person = (com.stono.servlet.bean.Person) _jspx_page_context.getAttribute("person", javax.servlet.jsp.PageContext.PAGE_SCOPE);
      if (person == null){
        person = new com.stono.servlet.bean.Person();
        _jspx_page_context.setAttribute("person", person, javax.servlet.jsp.PageContext.PAGE_SCOPE);
        out.write("\r\n");
        out.write("\t\t\t");
        org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person"), "name", request.getParameter("userName1"), request, "userName1", false);
        out.write("\r\n");
        out.write("\t\t");
      }
      out.write("\r\n");
      out.write("\t\tName is ");
      out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((com.stono.servlet.bean.Person)_jspx_page_context.findAttribute("person")).getName())));
      out.write("\r\n");
      out.write("\t</p>\r\n");
      out.write("\t<p>\r\n");
      out.write("\t\t");
      com.stono.servlet.bean.Person person2 = null;
      person2 = (com.stono.servlet.bean.Person) _jspx_page_context.getAttribute("person2", javax.servlet.jsp.PageContext.PAGE_SCOPE);
      if (person2 == null){
        person2 = new com.stono.servlet.bean.Person();
        _jspx_page_context.setAttribute("person2", person2, javax.servlet.jsp.PageContext.PAGE_SCOPE);
        out.write("\r\n");
        out.write("\t\t\t");
        org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person2"), "name", request.getParameter("name"), request, "name", false);
        out.write("\r\n");
        out.write("\t\t");
      }
      out.write("\r\n");
      out.write("\t\tName is ");
      out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((com.stono.servlet.bean.Person)_jspx_page_context.findAttribute("person2")).getName())));
      out.write("\r\n");
      out.write("\t</p>\r\n");
      out.write("\t<p>\r\n");
      out.write("\t\t");
      com.stono.servlet.bean.Person person3 = null;
      person3 = (com.stono.servlet.bean.Person) _jspx_page_context.getAttribute("person3", javax.servlet.jsp.PageContext.PAGE_SCOPE);
      if (person3 == null){
        person3 = new com.stono.servlet.bean.Person();
        _jspx_page_context.setAttribute("person3", person3, javax.servlet.jsp.PageContext.PAGE_SCOPE);
        out.write("\r\n");
        out.write("\t\t\t");
        org.apache.jasper.runtime.JspRuntimeLibrary.introspect(_jspx_page_context.findAttribute("person3"), request);
        out.write("\r\n");
        out.write("\t\t");
      }
      out.write("\r\n");
      out.write("\t\tName is ");
      out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((com.stono.servlet.bean.Person)_jspx_page_context.findAttribute("person3")).getName())));
      out.write("\r\n");
      out.write("\t\tAge is ");
      out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((com.stono.servlet.bean.Person)_jspx_page_context.findAttribute("person3")).getAge())));
      out.write("\r\n");
      out.write("\t</p>\r\n");
      out.write("\t\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

POJO:

package com.stono.servlet.bean;
public class Person {
    // 对外的属性名称还是name,
    private String name2;
    private Integer age;
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public String getName() {
        return name2;
    }
    public void setName(String name) {
        this.name2 = name;
    }
}
时间: 2024-09-30 15:49:13

JSP userBean setProperty直接从request中获取参数的相关文章

使用JavaScript获取url(request)中的参数

这次是使用JavaScript来获取url(request)中的参数 在日常页面编写的过程中为了方便操作在<script>中通过使用window.location.href="要跳转的页面?参数1="+值1+"&参数2="+值2  来进行页面跳转并传值. 那么在跳转过去的页面怎样在<script>中获取到传过来的参数呢? 下面是小编的一个案例: //参数传出页面 window.location.href = "Framese

request中获取post的json对象数据content-type=“text/plain”

其实采用http://www.cnblogs.com/SimonHu1993/p/7295750.html中的方法一都能获取到,就是通过获取request中的流数据,拿到json数据,理论上应该适用各种content-type的请求数据. /** *获取 request 中用POST方式"Content-type"是 * "text/plain"发送的 json数据 * @author: Simon * @date: 2017年8月6日 下午7:44:09 * @p

java获取request中的参数

1.用request.getParameterMap()获取url中的所有参数 Map map=request.getParameterMap(); Set keSet=map.entrySet(); for(Iterator itr=keSet.iterator();itr.hasNext();){ @SuppressWarnings("rawtypes") Map.Entry me=(Map.Entry)itr.next(); Object ok=me.getKey(); Obje

Django中获取参数(路径,查询,请求头,请求体)

一.通常HTTP协议向服务器传参有几种途径 : 提取URL的特定部分,如/weather/shanghai/2018,可以在服务器端的路由中用正则表达式截取: 查询字符串(query string),形如key1=value1&key2=value2: 请求体(body)中发送的数据,比如表单数据.json.xml: 在http报文的头(header)中. 1.URL中参数的获取 在定义路由URL时,可以使用正则表达式提取参数的方法从URL中获取请求参数,Django会将提取的参数直接传递到视图

JSP userBean setProperty getProperty指令使用

javaBean的属性取决于get/set方法,而不是真实的属性名称. jsp文件: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + req

Spring-boot 配置Aop获取controller里的request中的参数以及其返回值

首先在你的Maven的pom文件里加入aop的依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> 1 2 3 4 在spring boot里面一切配置都是很简单的,下面为我所有被请求到的controller加上Aop的功能吧,看码: pack

Spring拦截器从Request中获取Json格式的数据

内容如题 1.创建取值类 1 /** 2 * MyRequestWrapper.java 3 * 4 * @screen 5 * @author havery 6 */ 7 package com.newpp.core.interceptor; 8 9 import java.io.BufferedReader; 10 import java.io.ByteArrayInputStream; 11 import java.io.IOException; 12 import java.io.Inp

symfony 从request中获取当前登陆用户

$usernameToken = unserialize($request->getSession()->get('_security_main')); $user = $usernameToken->getUser();

从request中获取文件流的两种方式,配置文件上传大小

原文地址:https://blog.csdn.net/xyr05288/article/details/80692132 原文地址:https://www.cnblogs.com/liu1275271818/p/12117914.html