Home > Java > javaTutorial > body text

How to pass value to servlet in jsp

(*-*)浩
Release: 2020-09-18 15:37:53
Original
12435 people have browsed it

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:

<a href="AServlet?password=传输内容">文本</a>
Copy after login

Servlet code:

String d = request.getParameter("password");
Copy after login

Second type:

Transmit through the form value.

jsp page:

<form action="LoginServlet">
    <input type="text" name="username">
    <input type="text" name="password">
    <input type="submit" value="登录">
</form>
Copy after login

Servlet code:

String username = request.getParameter("username");
String password = request.getParameter("password");
Copy after login

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!

Related labels:
jsp
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!