How to handle HTML tags in java servlet program?

1) In my servlet program, I have an instruction that will be printed using the code as follows:

    out.println("<b>This is servlet output</b>");

Instead of printing in bold, it just prints with a tag in the browser itself.

How to fix the same?

2) In addition, on the servlet page, after submitting the jsp form, I want to add the below HTML tag to the java code of the servlet program.

    <a href="upload.jsp">Go to JSP form</a>

How to achieve the same? Please inform.

+3
source share
2 answers

1) The browser interprets your output as text, try adding

response.setContentType("text/html");

This line tells the browser that you are submitting HTML and that it should be interpreted in this way.

2) Same as bold text

out.println("<a href=\"upload.jsp\">Go to JSP form</a>");

, Servlet HTML- . , HTML.

JSP, JSP, .

:

1) servet_output.jsp

<b>My bold test</b>
<a href="upload.jsp">Go to JSP form</a>

2) JSP:

request.getRequestDispatcher("servlet_output.jsp").forward(request, response);

, , JSP .

+11

html.jsp - .

request.getRequestDispatcher("name.jsp").forward(request, response);

html-.

0

Source: https://habr.com/ru/post/1764609/


All Articles