无法获取< ...>中包含的文本区域内容在servlet中 [英] Can't get text area contents enclosed in <...> in servlet

查看:250
本文介绍了无法获取< ...>中包含的文本区域内容在servlet中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML页面中有一个带有textarea的表单,我正在尝试通过POST将其内容发送到servlet。问题是如果我在textarea中写了类似 unnclosed< enclosed> 的东西,当我调用 request.getParameter(textareaId)(其中 request HttpServletRequest 对象)在servlet的 service()方法中(扩展 HttpServlet) ),我只获得未封闭作为参数值。有没有办法获得textarea的完整内容?

I have a form with a textarea in an HTML page and I'm trying to send its contents to a servlet via POST. The problem is that if I write something like unenclosed <enclosed> in the textarea, when I call request.getParameter("textareaId") (where request is a HttpServletRequest object) in the service() method of the servlet (that extends HttpServlet), I get only "unenclosed" as parameter value. Is there any way to get the complete contents of the textarea?

Html代码:

<form action="MyServlet" method="post">
    <textarea name="MyTextarea" rows="5" cols="50"></textarea>
</form>

Servlet代码:

Servlet code:

public class MyServlet extends HttpServlet {
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String contents = request.getParameter("MyTextarea");
        System.out.println(contents);
    }
}

谢谢!

编辑:我通过在发送到servlet之前转义JavaScript函数中的textarea内容来解决它。

I solved it by escaping the textarea contents in a JavaScript function before sending it to the servlet.

推荐答案

这个 index.jsp 适用于Tomcat 6.0.35。我看到< > 打印到控制台。

This index.jsp works for me on Tomcat 6.0.35. I see the < and > printed to the console.

<%
    String contents = request.getParameter("MyTextarea");
    System.out.println(contents);
%>
<form method="post">
    <textarea name="MyTextarea" rows="5" cols="50"></textarea>
    <input type=submit>
</form>

您使用的是什么servlet容器?

What servlet container are you using?

默认情况下容器是否启用了任何参数转义?

Does the container have any parameter escaping turned on by default?

什么是默认字符编码(不能真正看出这是一个问题< > 是常规ASCII)?

What is the default character encoding (can't really see that being an issue as < and > are regular ASCII)?

这篇关于无法获取&lt; ...&gt;中包含的文本区域内容在servlet中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆