简体   繁体   English

JSP为request.getParameter()返回null,但在EL中显示值

[英]JSP returning null for request.getParameter() but shows values in EL

I am new to servlets and JSPs. 我是servlet和JSP的新手。 Recently.. I have been trying to send data from my Servlet to JSP using requestDispatcher. 最近..我一直在尝试使用requestDispatcher将数据从Servlet发送到JSP。

This is my Servlet code responsible: 这是我的Servlet代码负责:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        sampleClass sampleObject = new sampleClass(1, "myname");
        ObjectMapper mapper = new ObjectMapper();
        String jsonstring = mapper.writeValueAsString(sampleObject);
        request.setAttribute("values", jsonstring);
        request.setAttribute("valuees", "testing");
        request.getRequestDispatcher("/somejsp").forward(request, response);
    }

My JSP part responsible for retrieving data: 我的JSP部分负责检索数据:

${values}
${valuees}
<% 
    //out.println(Message);
    Enumeration enume = request.getParameterNames();
    for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue()[0];
        // ...
    }
    String value = request.getParameter("values");
    out.println(value);
    String valuee = request.getParameter("valuees");
    out.println(valuee);
 %>

But the output I get is: 但是我得到的输出是:

{"n":1,"name":"myname"} testing null null {“ n”:1,“ name”:“ myname”}测试null null

as you can see both the EL gives correct output, the implementation with the Enumeration returns nothing and the other two return null. 如您所见,两个EL都给出了正确的输出,带有Enumeration的实现不返回任何内容,而其他两个返回null。

I donot understand this. 我不明白这个。 I couldn't find any solution online. 我在网上找不到任何解决方案。

会将属性 (选择存储在请求中的任何对象,使用您选择的名称)与参数 (浏览器作为请求的一部分发送的字符串,如foo=bar&baz=2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM