cool hit counter Calling a variable in another JSP page in a JSP page_Intefrankly

Calling a variable in another JSP page in a JSP page

Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission.

In jsp learning, often need to call a variable in a jsp page in another jsp page, the following days of learning, summarized.

There are various ways to call variables between jsp pages.

1, through the built-in object of jsp - request object to obtain parameters.

(1) Passing of references by hyperlink.

Example: Passing the value of i from a.jsp to b.jsp.

The core code in the a.jsp page is.

<a href="b.jsp?i=1">pass on references</a>( instructions: fori The assignment can also be made withjsp expression (math.), for examplei=<% variable name %>)

The core code in the b.jsp page is.

<%String j=request.getParameter("i"); %>

<%=j %>

(2) By the request.setAttribute() method.

Example: Transfer the value of name from the form in a.jsp to b.jsp.

The core code in the a.jsp page is.


The core code in the b.jsp page is.

<%String getName=request.getParameter("name"); %>

(3) Passing a reference through a form.

Example: Transfer the value of name from the form in a.jsp to b.jsp.

The core code in the a.jsp page is.

<form action="b.jsp" method="post">


<li><input type="text" name="username">

<li>w<input type="submit" name="submit" value=" submit">



The core code in the b.jsp page is ;

<%String getUserName=request.getParameter("username");>

<%=getUserName %>

(4) Passing a reference through the hidden field of a form.

Example: Transfer the variables defined in a.jsp to b.jsp;

The core code in a.jsp is.

<%!int a=4; %> <form action="b.jsp" method="post"> <input type="hidden" name="b" value=<%a%>>

<input type="submit" value=" submit">


The core code in b.jsp is.

<%int c=(Integer)request.getAttribute("b"); %>

( The above code or for<%String c=request.getAttribute("c").toString(); %> wait a minute!, Type conversion passjava the same as) <%=c %>

Run result: the value of the variable a=4 is passed to c in b.jsp via the form hidden field b.

2. Obtaining form information through JavaBean.

Example: Getting user login form information with JavaBean.

 Login.jsp The core code in:
 <form action="Deal.jsp" method="post">
 <li> user ID:<input type="text" name="username">
 <li> pin number:<input type="password" name="password">
 <li><input type="submit" name="submit" value=" log in">
 JavaBean The core code in:
 package com;
 public class UserBean{
private String username;
 private String password;
 public String getUserName(){
 return username;
 publicvoid setUserName(String username){
 public String getPassword(){
 return password;
 public void setPassword(String password){

The core code in Deal.jsp is :

 <jsp:useBean id="user" class="com.UserBean" >
<jsp:setProperty name="user" property="*">
 <%String username=user.getUserName();%>
 <%String password=user.getPassword();%>
  The user name obtained is:<%=username%><br>
 The password obtained is:<%=password%>

among others,Deal.jsp hit the target<jsp:setProperty name="user" property="*"> The asterisk in the indicates that an assignment to all attributes with the same name, Of course it is also possible to selectively assign values to properties: <jsp:setProperty name="user" property="username">、<jsp:setProperty name="user" property="password"> etc.。

Surely there must be better and more ways to do this, and I look forward to the advice of the experts.

1、The first thing you need to do is to take a look at the following
2、Summary of the EnterLibPIAB In Depth blog post series
3、Creative brainstorming from the user
4、Blockchain will make the next Google
5、OA Satisfaction Analysis 2014 Brand Perception and Repurchase Indexes for Zhiyuan and Panmicro are indistinguishable

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送