text]; 2. Pass value through from form; 3. You can also pass values through java code."/> text]; 2. Pass value through from form; 3. You can also pass values through java code.">

Home>Article>Java> How to pass value to servlet in jsp

How to pass value to servlet in jsp

(*-*)浩
(*-*)浩 Original
2019-05-20 19:35:59 12369browse

When writing projects, the data of the front-end page is often transferred to the back-end server. That is, there are several ways to pass values from jsp to Servlet.

How to pass value to servlet in jsp

Method of jsp passing value to servlet:

First method:

Transfer value through hyperlink.

Jsp page:

文本

Servlet code:

String d = request.getParameter("password");

Second type:

Transmit through the form value.

jsp page:

Servlet code:

String username = request.getParameter("username"); String password = request.getParameter("password");

The third type:

can also be passed through java code Pass value,

java fragment code, the servlet can only receive the content of session.setAttribute("testSession", "Hello session"), but cannot receive the content of the request. Use request.getSession().getAttribute("testSession") in the servlet to obtain the session content.

It is not recommended to write like this, it will be very troublesome to maintain in the later stage.

The above is the detailed content of How to pass value to servlet in jsp. 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
Previous article:How does jsp work? Next article:How does jsp work?