0

HTML Page

<form action="viewParticularImage.jsp" method="post">
    input type="submit" name="1" value="Details" />
    input type="submit" name="2" value="Details" />
    input type="submit" name="3" value="Details" />
</from>

JSP page

<%
String name = request.getParameter("name");
out.write(name);    
%>

i am getting null value in name while printing the button Details in JSP Page pls help to find the solution, thanks to the replies in advance .

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
Selva
  • 546
  • 5
  • 12
  • 34

4 Answers4

1

You have parameters named as "1", "2" and "3", but you have not parameter named as "name".

<form action="viewParticularImage.jsp" method="post">
   <input type="submit" name="name" value="Details" />
   ...
</from>
Filipp Voronov
  • 4,077
  • 5
  • 25
  • 32
  • I'm not sure, but try to test for null or for equality with "Details" following values: request.getParameter("1"); request.getParameter("2"); request.getParameter("3"); see also: http://stackoverflow.com/questions/2129346/if-an-html-form-has-two-input-type-submit-buttons-how-do-i-know-which-got-c – Filipp Voronov Apr 02 '14 at 05:28
0

You are not sending a parameter named name in the request.That's why! To confirm, try

<%
String name = request.getParameter("1");
out.write(name);
%>

Your form should be like below. See the value of name attribute of the input text. The name attribute denotes the name of the request parameter

<form action="viewParticularImage.jsp" method="post">
  First name: <input type="text" name="name"><br>
  <input type="submit" value="Submit">
</form>

Note : Try entering a value in the text and submit. You will receive it in the server request

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
0

In your JSP page make it

<% String name = request.getParameter("1"); out.write(name); %>

Haritha
  • 391
  • 1
  • 9
0

I believe you haven't gained any knowledge regarding HTML ... First, go and check the tutorials regarding HTML...

Let's get to the game ... What are you trying to do ... Are you trying to pull down values set to the submit button ... or you are trying to publish a textfield where user can type their name and show that name as the result in the next page ????

If you are trying to publish the values assigned to the submit button...

HTML Page

<form action="viewParticularImage.jsp" method="post">
   <input type="submit" name="1" value="Details" />
   <input type="submit" name="2" value="Details" />
   <input type="submit" name="3" value="Details" />
</form>

JSP page

<%
   String name = request.getParameter("1");
   out.write(name);
%>

If you are trying to publish what users type ...

HTML Page

<form action="viewParticularImage.jsp" method="post">
   <input type="text" name="name" />
   <input type="submit" value="Hit Send" />
</form>

JSP page

<%
   String name = request.getParameter("name");
   out.write(name);
%>

I think this clarifies you how things work !!!! Thank you ... peace !!!

Roshan Shahukhal
  • 243
  • 4
  • 15