snipt

Ctrl+h for KB shortcuts

Java

Stream to String

1
2
3
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
https://snipt.net/embed/14f145a3a5201607e38146e124cf6585/
/raw/14f145a3a5201607e38146e124cf6585/
14f145a3a5201607e38146e124cf6585
java
Java
3
2019-07-16T13:36:32
True
False
False
/api/public/snipt/40663/
stream-to-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">StringWriter</span> <span class="n">writer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">StringWriter</span><span class="o">();</span> </span><span id="L-2"><a name="L-2"></a><span class="n">IOUtils</span><span class="o">.</span><span class="na">copy</span><span class="o">(</span><span class="n">inputStream</span><span class="o">,</span> <span class="n">writer</span><span class="o">,</span> <span class="n">encoding</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a><span class="n">String</span> <span class="n">theString</span> <span class="o">=</span> <span class="n">writer</span><span class="o">.</span><span class="na">toString</span><span class="o">();</span> </span></pre></div> </td></tr></table>
java, servlet, stream, string, tomcat

Java Server Page

Servlet to jsp forward

1
2
3
String nextJSP = "/somepage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
https://snipt.net/embed/db25fe78ee7e683bfd4718c49b28af6b/
/raw/db25fe78ee7e683bfd4718c49b28af6b/
db25fe78ee7e683bfd4718c49b28af6b
jsp
Java Server Page
4
2019-07-17T21:12:25
True
False
False
/api/public/snipt/13839/
servlet-to-jsp-forward
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>String nextJSP = &quot;/somepage.jsp&quot;; </span><span id="L-2"><a name="L-2"></a>RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); </span><span id="L-3"><a name="L-3"></a>dispatcher.forward(request,response); </span></pre></div> </td></tr></table>
forward, jsp, servlet