0

我有一个 jsp 页面,它在 get 参数中接受一个字符串mystring

http://localhost:8080/MyApp/index.jsp?mystring=

我正在尝试将此字符串放在<pre>标签内。

<body>
 <pre>
      <%= request.getParameter("mystring") %>
  </pre>
</body>

当我打电话时,http://localhost:8080/MyApp/index.jsp?mystring=<html>什么都没有打印。然后我尝试了 URLUTF8Encoder并且它适用于大多数标签但是当我通过这样的东西时:

<script>window.serq=[];StackExchange={ready:function(f){serq.push(f)}}</script>
    <title>Get SVG representation of div using jQuery SVG - Stack Overflow</title>
    <link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico">
    <link rel="apple-touch-icon" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
    <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
    <link rel="stylesheet" type="text/css" href="http://cdn.sstatic.net/stackoverflow/all.css?v=691f98480525">
    <meta name="relativepagescore" content="5555">
    <link rel="canonical" href="http://stackoverflow.com/questions/11340476/get-svg-representation-of-div-using-jquery-svg">
    <link rel="alternate" type="application/atom+xml" title="Feed for question 'Get SVG representation of div using jQuery SVG'" href="/feeds/question/11340476">
    <script type="text/javascript">
      StackExchange.ready(function () {
        StackExchange.realtime.init('ws://sockets.ny.stackexchange.com');
        StackExchange.realtime.subscribeToInboxNotifications();
        StackExchange.realtime.subscribeToReputationNotifications('1');            
      });
    </script>

我没有得到任何回应。

url编码后如下:

http://localhost:8080/SnippetImage/image.jsp?mystring=%3cspan+class%3d%22tag%22%3e%26lt%3bscript%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3ewindow%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3eserq%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%5b%5d%3b%3c%2fspan%3e%3cspan+class%3d%22typ%22%3eStackExchange%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%7b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3eready%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3a%3c%2fspan%3e%3cspan+class%3d%22kwd%22%3efunction%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e(%3c%2fspan%3e%3cspan+class%3d%22pln%22%3ef%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e)%7b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3eserq%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3epush%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e(%3c%2fspan%3e%3cspan+class%3d%22pln%22%3ef%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e)%7d%7d%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3b%2fscript%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%0a%0a++++%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3btitle%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3eGet+SVG+representation+of+div+using+jQuery+SVG+-+Stack+Overflow%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3b%2ftitle%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3blink%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3erel%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22shortcut+icon%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ehref%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22http%3a%2f%2fcdn.sstatic.net%2fstackoverflow%2fimg%2ffavicon.ico%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3blink%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3erel%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22apple-touch-icon%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ehref%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22http%3a%2f%2fcdn.sstatic.net%2fstackoverflow%2fimg%2fapple-touch-icon.png%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3blink%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3erel%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22search%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3etype%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22application%2fopensearchdescription%2bxml%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3etitle%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22Stack+Overflow%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ehref%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22%2fopensearch.xml%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a%0a%0a++++%0a%0a++++%0a%0a++++%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3blink%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3erel%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22stylesheet%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3etype%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22text%2fcss%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ehref%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22http%3a%2f%2fcdn.sstatic.net%2fstackoverflow%2fall.css%3fv%3d691f98480525%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3bmeta%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ename%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22relativepagescore%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3econtent%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%225555%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3blink%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3erel%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22canonical%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ehref%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22http%3a%2f%2fstackoverflow.com%2fquestions%2f11340476%2fget-svg-representation-of-div-using-jquery-svg%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3blink%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3erel%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22alternate%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3etype%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22application%2fatom%2bxml%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3etitle%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22Feed+for+question+'Get+SVG+representation+of+div+using+jQuery+SVG'%22%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3ehref%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22%2ffeeds%2fquestion%2f11340476%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a%0a%0a%0a%0a++++++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3bscript%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22atn%22%3etype%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%3d%3c%2fspan%3e%3cspan+class%3d%22atv%22%3e%22text%2fjavascript%22%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a+++++++++++++%3c%2fspan%3e%3cspan+class%3d%22typ%22%3eStackExchange%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3eready%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e(%3c%2fspan%3e%3cspan+class%3d%22kwd%22%3efunction%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e()%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e+%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%7b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a+++++++++++++++++%3c%2fspan%3e%3cspan+class%3d%22typ%22%3eStackExchange%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3erealtime%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3einit%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e(%3c%2fspan%3e%3cspan+class%3d%22str%22%3e'ws%3a%2f%2fsockets.ny.stackexchange.com'%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e)%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++++++++++++++%3c%2fspan%3e%3cspan+class%3d%22typ%22%3eStackExchange%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3erealtime%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3esubscribeToInboxNotifications%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e()%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++++++++++++++%3c%2fspan%3e%3cspan+class%3d%22typ%22%3eStackExchange%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3erealtime%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e.%3c%2fspan%3e%3cspan+class%3d%22pln%22%3esubscribeToReputationNotifications%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e(%3c%2fspan%3e%3cspan+class%3d%22str%22%3e'1'%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e)%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e++++++++++++%0a%0a++++++++%3c%2fspan%3e%3cspan+class%3d%22pun%22%3e%7d)%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%0a++++++++%3c%2fspan%3e%3cspan+class%3d%22tag%22%3e%26lt%3b%2fscript%26gt%3b%3c%2fspan%3e%3cspan+class%3d%22pln%22%3e%0a%3c%2fspan%3e

我在这里做错了什么?有什么办法可以在不编码的情况下显示html?

  • 我只需要发送一个 GET 请求。不是 POST 请求。
  • 没有javascript。
4

2 回答 2

1

url编码后如下: http://localhost:8080/SnippetImage/image.jsp?code=%3cspan...

请注意,您的参数mystring在您的 URL 字符串中不存在。因此,您的 jsp 页面将一无所获。

另请注意,http url 有一个最大长度,我只是在猜测,但看起来你可能会遇到硬限制。如果是,则此编码返回的方式可能无法预测。

于 2012-07-06T15:58:38.737 回答
0

试试这个:

<%= request.getParameter("mystring").replaceAll("<","&lt;").replaceAll(">","&gt;") %>
于 2012-07-06T16:25:58.933 回答