Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return an html document from java servlet?
    primarykey
    data
    text
    <p>This works to return a string:</p> <pre><code>import javax.servlet.http.*; @SuppressWarnings("serial") public class MonkeyServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.getWriter().println("got this far"); } } </code></pre> <p>But I can't get it to return an html document. This doesn't work:</p> <pre><code>import javax.servlet.http.*; @SuppressWarnings("serial") public class BlotServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/html"); resp.getWriter().println("html/mypage.html"); } } </code></pre> <p>Sorry for being noob!</p> <p>EDIT:</p> <p>I already have the html in separate documents. So I need to either return the document, or read/parse it somehow, so I'm not just retyping all the html...</p> <p>EDIT:</p> <p>I have this in my web.xml</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;Monkey&lt;/servlet-name&gt; &lt;servlet-class&gt;com.self.edu.MonkeyServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Monkey&lt;/servlet-name&gt; &lt;url-pattern&gt;/monkey&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Is there something else I can put in there so it just returns a file, like...</p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;Monkey&lt;/servlet-name&gt; &lt;file-to-return&gt;blot.html&lt;/file-to-return&gt; &lt;/servlet-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload