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>

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.