HTML code appears while executing jsp page

2020-05-06 15:36发布

问题:

HTML code appears when I try to execute the jsp page. This appears in the browser.

I tried to change the contentType and language in the tag. But it did not work.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<HTML>
<HEAD> <TITLE> The Welcome JSP  </TITLE> </HEAD>
<BODY>

<H3> Welcome! </H3>
<P><B> Today is <%= new java.util.Date() %>.  Have a nice day! </B></P>
</BODY>
</HTML>

This is my servlet code.

public class Add extends HttpServlet {
    public void service(HttpServletRequest rq, HttpServletResponse rs)throws IOException, ServletException
    {
        int i=Integer.parseInt(rq.getParameter("t1"));
        int j=Integer.parseInt(rq.getParameter("t2"));
        int k=i+j;
        PrintWriter out=rs.getWriter();
        out.println("The sum is:"+k);
        RequestDispatcher rd=rq.getRequestDispatcher("/Welcome.jsp");
        rd.include(rq,rs);
    }

}

I want the code to get rendered and view the output.