JSP常用标签
jsp代码:
<%-- 和pageContext.include()一样效果,动态包含--%> <jsp:include page="/1.jsp"></jsp:include>
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <jsp:forward page="/servlet/IndexServlet"></jsp:forward> </body> </html>PS:因为web.xml中配置首页只能是jsp, 而首页往往需要servlet处理数据,所以就在首页index.jsp中使用来转发到servlet。
<jsp:forward page="/servlet/IndexServlet"></jsp:forward>
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jsp常用标签</title> </head> <body> <% int x = 10; %> <jsp:forward page="/servlet/ServletDemo1"> <jsp:param name="username" value="<%=x %>"/> <jsp:param name="password" value="123"/> <jsp:param name="username" value="<%=x %>"/> </jsp:forward> </body> </html>Servlet代码:
public class ServletDemo1 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); System.out.println(username); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }