我尝试将输入值从login.jsp发送到sentUser.jsp,
我看到了很多解决方案,但问题是每个解决方案都以login.jsp的形式将sentUser.jsp作为操作传递。
在我的例子中,我使用action来验证数据,但是我不能删除它。
求求你,我需要解决方案。我只是想将username的值传递给另一个JSP或java函数。
此login.jsp
<form class="/servletLogin" method="post" onSubmit="return validate();"
action="http://erpteskjgo01.join.gov.jo:5436/mjn/server/auth_save_click" id="LoginForm">
<h3 class="loginTitle">login</h3>
<div class="col-md-12">
<div class=" form-group">
<label for="Username">username</label>
<input type="text" class="form-control focus" maxlength="50" placeholder="username"
data-val="true" data-val-required="please enter username" id="username"
name="username" />
<span class="field-validation-valid" data-valmsg-for="Username"
data-valmsg-replace="true"></span>
</div>
</div>
<div class="col-md-12">
<div class=" form-group">
<label for="Password">password</label>
<input type="password" class="form-control focus" maxlength="50" placeholder="password"
data-val="true" data-val-required="please enter password" id="password"
name="password" />
<span class="field-validation-valid" data-valmsg-for="Password"
data-valmsg-replace="true"></span>
</div>
</div>
<div class="col-md-12">
<a id="link" href="${pageContext.request.contextPath}/servletLogin" style="visibility: hidden; color: red;">can't login?</a>
</div>
<label id="mylocation"></label>
<div class="col-md-12 col-sm-12 col-xs-12 padd0">
<span class="sperator"></span>
<input type="hidden" name="request_id" value="=reqId>">
<button class=" searchBtn" name="button" value="login">enter</button>
</div>
</form>```
//////////////////////////////////////////////////////////////////////////
and this page i want to get the value in it sentUser.jsp
``` <body> <% String u1 = request.getParameter("username"); System.out.print("Heloooooo"+u1);%>发布于 2019-11-07 16:58:49
您可以使用Java-backend通过Rest-endpoint传递所需的值。在JSF中使用c:url标记检索此值:
<c:url value="pathToValue?jsfVariableName=${backendLoginVariable}" />现在,变量jsfVariableName包含了请求的登录信息。
<a href="<c:out value="${backendLoginVariable}"/>">get-variable-value</a>应该行得通。
发布于 2019-11-07 18:01:57
使用setAttribute(..)方法可以很容易地做到这一点。只需执行以下操作。
在first.jsp中
request.setAttribute("key", value);
在second.jsp中
Object val = request.getAttribute("key");
但请记住,您必须包含来自first.jsp的second.jsp
在first.jsp中
<jsp:include page="./second.jsp">
</jsp:include>额外的好处:你也可以在引入second.jsp的时候设置参数
在first.jsp中
<jsp:include page="./second.jsp">
<jsp:param name="key" value="value_from_first_jsp"/>
</jsp:include>在second.jsp中
String value = request.getParameter("key")https://stackoverflow.com/questions/58744452
复制相似问题