Click here to Skip to main content
16,017,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<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>


here,i want to print the drop down items ,which print null..anybody please help me out?
Posted
Updated 10-Jul-13 6:58am
v2

1 solution

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
<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>

In java class,
Java
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());
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900