我想將我的信息從servlet顯示到JSP頁面。Servlet到JSP數據顯示
我嘗試了很多可能的事情,但它是空的。
所以我寫了只有一個參數顯示的程序,它也是空的。
JSP頁面:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="ci1" method="get">
User Name : <% String name1 = request.getParameter("name");
out.print(name1); %>
</form>
</body>
</html>
web.xml中: -
的Servlet: -
public class control_it {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name = "Display the name";
request.setAttribute("name", name);
request.getRequestDispatcher("try_it.jsp").forward(request, response);
}
}
Servlet的必須是子類的'HttpSevlet'。請使用適當的命名約定來命名您的班級和其他成員。 – adatapost
創建RequestDispatcher rd = request.getRequestDispatcher(「ur html」); –