File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Unable to get value of URL parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to get value of URL parameter" Watch "Unable to get value of URL parameter" New topic
Author

Unable to get value of URL parameter

Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Im trying to pass an value between a jsp-file and a servlet. The only output Im getting when Im trying so display getParameterValues("name") is this: "[Ljava.lang.String;@178655 " the numbers arfter the @ changes after evry refresh. Im really new to this so what I need is basic instructions. Here is my jsp, note Ive go the same result when I tried change the actionvalue to action="test/first?name".
JSP:
<form name="f1" METHOD="POST" action="f1/first">
<input name="name" type="text">
<input type="Submit">
And the servlet:
public void doGet(HttpServletRequest myRequest, HttpServletResponse myResponse){
String gh = myRequest.getParameter("name");
myResponse.setContentType("text/html");
PrintWriter myWriter=myResponse.getWriter();
myWriter.println(header);
myWriter.println(gh);
}


/ Sebastian<br />No blog, No homepage, No life?
Ben Dover
Ranch Hand

Joined: Jan 30, 2004
Posts: 91
Hi Sebastion,
Since your form uses "POST", you need to utilise the doPost() method in your servlet, here is one way of achieving this:

[ January 31, 2004: Message edited by: Louis M@lenica ]
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Im getting a HTTP 500 Server error when Im trying to execute the servlet without parameter in the adressfield. Got any general ideas? Btw, it works fine when i use a parameter.
[ January 31, 2004: Message edited by: Sebastian Green ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
When using getParameterValues( somename ) the returned reference is a String array. Thats what the [java.lang.String is trying to tell you.
Use getParameterValues when you have a Form that has mutiple checkboxes or other input item with the same name.
When you are sure there is only one parameter, use getParameter( somename )
Bill
Ben Dover
Ranch Hand

Joined: Jan 30, 2004
Posts: 91
Originally posted by Sebastian Green:
Im getting a HTTP 500 Server error when Im trying to execute the servlet without parameter in the adressfield. Got any general ideas? Btw, it works fine when i use a parameter.
[ January 31, 2004: Message edited by: Sebastian Green ]

Sebastion,
be sure to check in your servlet that the parameter is not empty. If it it, simply redirect to the form. in your jsp page, set the errorPage directive to an error.jsp page. In the error.jsp set the isErrorPage directive to true. You can also throw an illegalArgumentException in your servlet if the parameter/s is/are invalid, then in the error.jsp page you can print out the details of your exception.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to get value of URL parameter