0

Hi I am new to JSP, if some could help me in understanding what is wrong in this code

<html>
<body>
<%String newname="hi"; %>
<%=request.getParameter("name")%>
<input type=text value="<%=newname %>" name="newname">

<%
newname=request.getParameter("newname");
out.println(newname);

String modifyurl = "delete.jsp?newname="+newname+"";
out.println("<td><a href ="+modifyurl+">Modify</a></td></tr><br>");


so when i print newname it always says null... please help



%>

</body>
</html>

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by parry_kulk
0

One thing you must always remember while dealing JSP or any server side scripting is that the server side code is executed first at the server than the resulted HTML is sent to the browser.
So in the code snippet given above all the java code between <%= %>, and <% %> will be executed on the web-server first. So any request.getParameter() statement will be executed before the page is rendered. You are getting the null value because the value of "newname" input field is not submitted yet.
Only after you submit a page containing the "newname" input field you will be able to read it using request.getParameter("newname")
Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.