Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to get value of URL parameter

 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
Ben Dover
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic