Jsp框架

package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JspServlet extends HttpServlet {

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	//转发动作到一个jsp 
	List list = new ArrayList();
	list.add("zhangsan 18");
	list.add("lisi 28");
	list.add("wang5 38");
	list.add("zhao6 10");
	
	request.setAttribute("name", "value");
	request.setAttribute("list", list);
	request.getRequestDispatcher("/servletJsp1.jsp").forward(request, response);
	
	//重定向到一个jsp

// response.sendRedirect("/jspday1/servletJsp1.jsp?name=xiaozhang");

}

}
package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletConfigTest extends HttpServlet {

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	ServletConfig config = this.getServletConfig();
	String name = config.getServletName();
	String initParameter = config.getInitParameter("name");
	
	PrintWriter out = response.getWriter();
	out.println("servletname is:"+name);
	out.println("initParameter is:"+initParameter);
	
}

你可能感兴趣的:(可视化,jsp,java,spring,servlet)