Home > Web Front-end > JS Tutorial > body text

How to create dynamic pages-using JSP and Java code

一个新手
Release: 2017-09-07 10:12:27
Original
1942 people have browsed it


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() {
    ...
    }
}
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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() {
    ...
    }
}
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!