如何配置安装servlet/jsp开发环境
1个回答
展开全部
要配置和使用servlet,需要一些前置条件
1、安装java运行时环境(jdk或jre)
2、安装web服务器,如tomcat
以下以tomcat环境为例讲解。
1、编写servlet类
package test.java.servelt;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
protected void doGet( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println( "This is a servlet TestServlet." );
out.flush();
}
}
2、web项目中的web.xml中配置
TestServlet
test.java.servlet.TestServlet
TestServlet
/testServlet
3、将servlet类编译好,放置到tomcat的文件夹下:\webapps\myapp\WEB-INF\classes\test\java\TestServlet.class,并启动tomcat
4、在浏览器中输入即可访问
1、安装java运行时环境(jdk或jre)
2、安装web服务器,如tomcat
以下以tomcat环境为例讲解。
1、编写servlet类
package test.java.servelt;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
protected void doGet( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println( "This is a servlet TestServlet." );
out.flush();
}
}
2、web项目中的web.xml中配置
TestServlet
test.java.servlet.TestServlet
TestServlet
/testServlet
3、将servlet类编译好,放置到tomcat的文件夹下:\webapps\myapp\WEB-INF\classes\test\java\TestServlet.class,并启动tomcat
4、在浏览器中输入即可访问
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询