2 回答

TA貢獻1825條經(jīng)驗 獲得超4個贊
${}
@WebServlet("/hello")public class HelloWorldServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String message = "Hello World"; request.setAttribute("message", message); // This will be available as ${message} request.getRequestDispatcher("/WEB-INF/hello.jsp").forward(request, response); }}
/WEB-INF/hello.jsp
<!DOCTYPE html><html lang="en"> <head> <title>SO question 2370960</title> </head> <body> <p>Message: ${message}</p> </body></html>
Message: Hello World
我們的servlet wiki頁面
servlet是如何工作的?實例化、會話、共享變量和多線程
Servlet中的doGet和doPost
在頁面加載時從JSP文件中調(diào)用servlet
提交HTML表單時如何將數(shù)據(jù)從JSP傳輸?shù)絪ervlet
使用MVC和DAO模式在JSP頁面中顯示JDBCResultSet
如何使用servlet和Ajax?
servlet返回“HTTP狀態(tài)404請求的資源(/servlet)不可用”

TA貢獻1863條經(jīng)驗 獲得超2個贊
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Hola</title>"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("</body>"); out.println("</html>");}
添加回答
舉報