从下拉列表中获取数据并打印 [英] get data from dropdownlist and print

查看:63
本文介绍了从下拉列表中获取数据并打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
   <script language="javascript" type="text/javascript">
   fun();
   {

       <%
       try{
       GetMenuData gm = new GetMenuData();
       String str =gm.displayData(request.getParameter("menuitems");
        System.out.println(str);
        }
       catch(Exception exp)
       {System.out.println(exp.getMessage());}
       %>
       out.println(str);
   }

 </script>

<head>
<title>Insert title here</title>
</head>
<body>
<form name="from1" action="index.jsp" method="get">
<input type =text name="urltext">
Listed menu:
<select name="menuitems" onChange="selectChanged(this);">
<option>select...   </option>
<option value = "Products">Products</option>
<option value="Solutions">Solutions</option>
<option value="Views">Views</option>
<option value="Services">Services</option>
<option value="About">About</option>
<option value="Support">Support</option>

</select>

<br/><br/>


 </form>
 <input type="submit" name="btn" value="submit" onclick="fun()">
</body>
</html>





在这里,我想打印下拉项目,打印null ..有人请帮帮我吗?



here,i want to print the drop down items ,which print null..anybody please help me out?

推荐答案

你好!



读完你的问题之后,我认为它有一些问题。我无法想象你在这个页面中使用Scriptlet代码的目的是什么。在提交表单之前,您不能使用request.getParameter()方法。无法在scriptlet中使用html值。但是,您可以在HTML标记中使用scriptlet值。对于您的代码,我建议将scriptlet代码移动到服务器端。然后,它会没事的。这是我的示例代码... ^^

在index.jsp中,

Hello!

After reading your question, I think it has some issues. I cannot think what is your purpose of using Scriptlet code in this page. You cannot use "request.getParameter()" method, before the form is submitted. There is no way to use html values in scriptlet. But, you can use scriptlet values in HTML tags. For your code, I would suggest to move the scriptlet code to server side. Then, it gonna be ok. Here's my sample code for you...^^
In index.jsp,
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<form action="servletUrl" method="get">
		<input type=text name="urltext"> Listed menu: 
		<select	name="menuitems" onChange="selectChanged(this);">
			<option>select...</option>
			<option value="Products">Products</option>
			<option value="Solutions">Solutions</option>
			<option value="Views">Views</option>
			<option value="Services">Services</option>
			<option value="About">About</option>
			<option value="Support">Support</option>
		</select> 
		<br />
		<br />
		<input type="submit" name="btn" value="submit">
	</form>
	
</body>
</html>



在java类中,


In java class,

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    try{
        GetMenuData gm = new GetMenuData();
        String str = gm.displayData(request.getParameter("menuitems"));
        System.out.println(str);
    }catch (Exception exp) {
        System.out.println(exp.getMessage());
    }
}


这篇关于从下拉列表中获取数据并打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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