jsp servlets和beans下拉列表 [英] jsp servlets and beans dropdown list

查看:61
本文介绍了jsp servlets和beans下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DropDownList显示我在列表中选择的项目。我得到它以请求响应为页面服务

但它是默认我希望有人能告诉我如何使列表显示我选择的项目。

PS。我是编程的新手所以你能解释一下发生了什么吗?

这是我的代码

DropDownList to show the item I selected in the list. I get it to serve the page with a request response
but it goes to the default I was hoping if someone could show me how to make the list show the Item I picked.
PS. I''m very new to programing so could you please explain what is going on as well
This is my code

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>clock</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
	Current date and time on server
	${requestScope.time}
	Use this form to select another format
	<form action="${pageContext.request.contextPath}/clock" method="post">
		Select format <select name="format">
			<option value="full" selected>full</option>
			<option value="long" selected>long</option>
			<option value="medium" selected>medium</option>
			<option value="short" selected>short</option>
			<option value="bad">bad</option>
		</select> and click <input type="submit" name="getTime" value="Get Time">
		
	</form>
</body>
</html>

推荐答案

{requestScope.time}
使用此表单选择其他格式
< form action =
{requestScope.time} Use this form to select another format <form action="


{pageContext.request.contextPath} / clockmethod =post>
选择格式< select name =format>
< option value =fullselected> full< / option>已选择
< option value =long> long< / option>
< option value =mediumselected> medium< / option>
< option value =shortselected> short< / option>
< option value =bad> bad< / option>
< / select>然后单击< input type =submitname =getTimevalue =Get Time>

< / form>
< / body>
< / html>
{pageContext.request.contextPath}/clock" method="post"> Select format <select name="format"> <option value="full" selected>full</option> <option value="long" selected>long</option> <option value="medium" selected>medium</option> <option value="short" selected>short</option> <option value="bad">bad</option> </select> and click <input type="submit" name="getTime" value="Get Time"> </form> </body> </html>


如果我理解正确,那么您需要在发送请求之前设置下拉列表。

在这种情况下,您必须返回选定的选项作为回应并执行以下操作:



If I understood properly, then you want to set the drop down list whatever you select before sending the request.
In that case you have to return back the selected option in response and do the following :

var textToFind = 'medium';//value read from scope variable

var dd = document.getElementById('formatId');
for (var i = 0; i < dd.options.length; i++) {

    if (dd.options[i].text === textToFind) {

        dd.selectedIndex = i;

        break;

    }

}





注意:下拉列表后调用此方法



Note:Call this method after drop down is list


这篇关于jsp servlets和beans下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆