今天换一个运行方式
安装这个exe,默认路径
首先新建一个项目servlet,点击next
点击next
修改项目名,并修改路径,并点击Finish
接下新建包,结构如下
下一步点击Add Configuration
点击+号,选择Tomcat server+Local
进入这个页面后,修改名字
接下来点击Configure,在左上角有个加号,找到jsp-api.jar和servlet-api.jar并添加
接下来点击 右上角的加号,并找到之前装的默认路径,点击ok就安装好了,
在servlet包里新建java class文件
HelloServlet
代码如下
package com.zhongruan.servlet;
import javax.servlet.*;
import java.io.IOException;
public class HelloServlet implements Servlet {
public HelloServlet(){
System.out.println(“构造方法”);
}
@Override
public void init(ServletConfig servletConfig) throws ServletException {
System.out.println(“init”);
}
@Override
public ServletConfig getServletConfig() {
return null;
}
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println(“service”);
}
@Override
public String getServletInfo() {
return null;
}
@Override
public void destroy() {
System.out.println(“destroy”);
}
}
login代码如下
package com.zhongruan.servlet;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
public class login extends GenericServlet {
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
}
}
zhuce代码如下
package com.zhongruan.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class zhuce extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write(“I am your father!”);
}
}