1. Create a java class that inherits the httpserlet abstract class.
public class SxtServlet extends HttpServlet{ //初始化servlet public void init() throws ServletException { ... } //实现主要功能 @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } //销毁servlet @Override public void destroy() { ... } }
2. Find the WebRoot/WEB-INF/web.xml file and write the following code:
<servlet> <!-- java类名--> <servlet-name>SxtServlet</servlet-name> <!-- java路径 --> <servlet-class>sxt.com.SxtServlet</servlet-class> </servlet> <servlet-mapping> <!-- java类名 --> <servlet-name>SxtServlet</servlet-name> <!-- 表单中action连接的名字(自己起) --> <url-pattern>/login</url-pattern> </servlet-mapping>
3. In the jsp page, the words written in action="" must match The same and add a / in front.
<form action="login" method="post"> ... </form>
1. Create a java class that inherits the httpserlet abstract class.
public class SxtServlet extends HttpServlet{ //初始化servlet public void init() throws ServletException { ... } //实现主要功能 @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } //销毁servlet @Override public void destroy() { ... } }
2. Find the WebRoot/WEB-INF/web.xml file and write the following code:
<servlet> <!-- java类名--> <servlet-name>SxtServlet</servlet-name> <!-- java路径 --> <servlet-class>sxt.com.SxtServlet</servlet-class> </servlet> <servlet-mapping> <!-- java类名 --> <servlet-name>SxtServlet</servlet-name> <!-- 表单中action连接的名字(自己起) --> <url-pattern>/login</url-pattern> </servlet-mapping>
3. In the jsp page, the words written in action="" must match The same and add a / in front.
<form action="login" method="post"> ... </form>
The above is the detailed content of How to create dynamic pages-using JSP and Java code. For more information, please follow other related articles on the PHP Chinese website!