Home > Back-end >  Why javaweb run in HTML code
Why javaweb run in HTML code

Time:09-27

How do my servlet file to run the HTML code to solve

Package: com.org;
import java.io.IOException;
import java.io.PrintWriter;

The import javax.mail. Servlet. ServletConfig;
The import javax.mail. Servlet. ServletException;
The import javax.mail. Servlet. The annotation. WebServlet;
The import javax.mail. Servlet. HTTP. HttpServlet;
import javax.servlet.http.HttpServletRequest;
The import javax.mail. Servlet. HTTP. HttpServletResponse;

/* *
* the Servlet implementation class CountServlet
*/
@ WebServlet ("/CountServlet ")
Public class CountServlet extends the HttpServlet {
private static final long serialVersionUID=1L;
Int count;
/* *
* @ see HttpServlet# HttpServlet ()
*/
Public CountServlet () {
super();
//TODO Auto - generated constructor stub
}
Public void init (ServletConfig config) throws ServletException {
The count=100;

}

/* *
* @ see HttpServlet# doGet (it request, HttpServletResponse response)
*/
Protected void doGet (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
Request. SetCharacterEncoding (" utf-8 ");
The response. SetContentType (" text/HTTML; charset=UTF-8");
PrintWriter out=response.getWriter();
count++;
Out.println (" & lt; HTML> & lt; HEAD> & lt; TITLE> Hello! & lt;/TITLE> & lt;/HEAD>" );
Out.println (" & lt; BODY> & lt; The H2 & gt; Hello! This web site is visited "+ count +" & lt;/BODY> & lt;/HTML>" );
Out.println (" ");
out.close();
}

/* *
* @ see HttpServlet# doPost (it request, HttpServletResponse response)
*/
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
DoGet (request, response);
}

}

CodePudding user response:

According to the page's content, printed by means of flow directly, this is the way operations are old,

CodePudding user response:

PrintWriter class, create an object, according to the front-end DOM format output
  • Related