Home  >  Article  >  Web Front-end  >  How to create dynamic pages-using JSP and Java code

How to create dynamic pages-using JSP and Java code

一个新手
一个新手Original
2017-09-07 10:12:271923browse


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn