Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Sample code error - method getParameters

Thread view: 
cliveswan@yahoo.co.uk - 02 Jul 2007 10:25 GMT
Hi,

I get an method getParameters error when running the sample code.
I looked for a org.javax.jar to import, could not find it??

Could anyone help to point out what is wrong.

Thanks

Clive

Error(38,1): method getParameters(java.lang.String) not found in
interface javax.servlet.http.HttpServletRequest

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page
   import = "java.lang.*"
   import = "javax.servlet.*"
   import = "java.lang.*"
   %>
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested"
prefix="nested"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-
template"prefix="template"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
prefix="tiles"%>
<html>
 <head>
   <meta http-equiv="Content-Type" content="text/html;
charset=windows-1252"/>
   <title>Home</title>
   <style type="text/css">
     body {
     background-color: #ffa5ff;
}
     a:link { color: #0000ff; }
   </style>
 </head>
 <body>

 <select name="menuName" size="1">
  <option value="Value0" selected>Yes</option>
  <option value="Value1">No</option>
</select>

<%
String sn1;
String sn2;

sn1 = request.getParameters("Value0");
sn2 = request.getParameters("Value1");

// n1 = Integer.ParseInt(sn1);

out.println("Value is" sn1 + sn2);
%>

 </body>
</html>
stefanomnn - 02 Jul 2007 10:37 GMT
hi, correct method is getParameter, without final "s".

if you have multi values for a parameter (such us in checkbox), you
can use

String[] getParameterValues(String paramName)

Stefano
cliveswan@yahoo.co.uk - 02 Jul 2007 10:53 GMT
Hi Stefano,

Thanks for pointing out the typo, really silly & annoying.

I corrected the typo still getting error (line 34, ; required??)

I understand sn1 = getParameter("Value0");

I do not understand the: String[] getParameterValues(String paramName)
How do you assign this??

Thanks for your assistance.

clive

> hi, correct method is getParameter, without final "s".
>
[quoted text clipped - 3 lines]
>
> Stefano
stefanomnn - 02 Jul 2007 11:08 GMT
Hi,
suppose you have this in your form:
<input type="ceckbox" name="selectedColors" value="red"/>Red
<input type="ceckbox" name="selectedColors" value="yellow"/>Yellow
<input type="ceckbox" name="selectedColors" value="green"/>Green

in your jsp,

String[] colors=  request.getParameterValues("selectedColors");
// colors have just colors user selected

Stefano :-)
cliveswan@yahoo.co.uk - 02 Jul 2007 13:29 GMT
Hi Stefano,

Noticed that I left out the System before out.println

I have amended the code, but am still getting an error >>> ; expected

I have pasted the revised code below.
PS thanks for your patience.

//>>>>>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page
   import="java.lang.*"
   import="javax.servlet.*"
   import="java.lang.*"
   %>
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
 <head>
   <meta http-equiv="Content-Type" content="text/html;
charset=windows-1252"/>
   <title>Home</title>
   <style type="text/css">
     body {
     background-color: #ffa5ff;
}
     a:link { color: #0000ff; }
   </style>
 </head>
 <body>

   <select name="roofTopdrop" size="1">
     <option value="Roof0" SELECTED>Yes</option>
     <option value="Roof1">N0</option>
     <option value="Roof2">-</option>
   </select>

// n1 = Integer.ParseInt(roofTopdrop);
<%
String[] roofTop = request.getParameterValues("roofTopdrop");
System.out.println("Value is" roofTop);
%>

 </body>
</html>
cliveswan@yahoo.co.uk - 02 Jul 2007 14:10 GMT
Hi Stefano,

Error, the System.out.println was within the <% %>, did not seem to
like that.

The JSP is creating website with drop-down listbox.
It prints out the System.out.println("Value is" roofTop);
Rather than the option selected in drop-down????

Thanks

Clive
stefanomnn - 02 Jul 2007 14:24 GMT
A combobox is a single value parameter.
so, you have to recovery value with request.getParameter("yourCombo");

you have some confusion with jsp,
see SUN tutorial:  http://java.sun.com/javaee/5/docs/tutorial/doc/JSPIntro.htm


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.