Get the App
SLTechnology News&Howtos  ›  Development  › 

How to test a JSP container

Shulou Source: shulou.com Published: 2022-06-02 12:31:54 09月12日 Update

This article is about how to test a JSP container. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Because the example given above is complicated. It's hard for most people to understand. I am also ^ _ ^, but if I look at it carefully, I will write a relatively simple one myself. I hope you will discuss it together. JSP container being tested

${name}

${pass}

Ant puts it directly in the root directory of the eclipes project, build.xml, but has three parameters to set the address of tomcat.home Tomcat, the root directory of the webapp.path project, and the WEB-INFsrc source code below (then JSP will be translated into .java to the org.apache.JSP.JSP of this directory)

TEST

Package jetty.test.supper; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.jsp.jsp.MyJsp_jsp; import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; import com.meterware.servletunit.InvocationContext; import com.meterware.servletunit.ServletRunner; import com.meterware.servletunit.ServletUnitClient; import junit.framework.TestCase; public class JSPCTest extends TestCase {private InvocationContext ic = null Protected void setUp () throws Exception {ServletRunner sr = new ServletRunner (); / / register jsp sr.registerServlet ("HelloWorld", MyJsp_jsp.class.getName ()); ServletUnitClient sc = sr.newClient (); WebRequest request = new GetMethodWebRequest ("http://localhost/HelloWorld"); ic = sc.newInvocation (request);} public void testJspC () throws Exception {HttpServletRequest re = ic .getRequest (); HttpServletResponse rq = ic.getResponse () Re.setAttribute ("name", "liukaiyi"); re.setAttribute ("pass", "123456"); MyJsp_jsp is = (MyJsp_jsp) ic.getServlet (); is._jspService (re,rq); WebResponse response = ic.getServletResponse (); / / output System.out.println (response.getText ());}}

As a result,

Liukaiyi

123456

Thank you for reading! This is the end of the article on "how to test the JSP container". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Containers tests content engineering more root directory articles good complex practical due time code due time parameters addresses articles environment directories see knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi MariaDB Shulou Information Microsoft