Displaying values in jsp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prasanthgkrishna
    New Member
    • Mar 2008
    • 1

    Displaying values in jsp

    Hi,

    How do I display the two values accepted from the user in the same page. One is the Username and the Other is Path of the file he had picked from <input type="file"./>
  • techheartbeat
    New Member
    • Mar 2008
    • 1

    #2
    Hello

    Try to assign the contents of your form parameters to variables...

    Code:
    <%@ page import="java.util.Map"%>
    <%
    Map params = request.getParameterMap();
    String userName = "";
    String fileName = "";
    try{
      userName = ((String[])params.get("username"))[0];
    }catch(Exception e){}
    try{
      fileName = ((String[])params.get("filename"))[0];
    }catch(Exception e){}
    %>
    ...and include these variables again in your page:

    Code:
    username=<%=userName%>, filename=<%=fileName%>

    Here's a complete example:

    Code:
    <%@ page import="java.util.Map"%>
    <%@ page session="false"%>
    
    <%
    Map params = request.getParameterMap();
    String userName = "";
    String fileName = "";
    try{
      userName = ((String[])params.get("username"))[0];
    }catch(Exception e){}
    try{
      fileName = ((String[])params.get("filename"))[0];
    }catch(Exception e){}
    %>
         <html>
         <head>
         <title>Test</title>
         </head>
    
         <body>
         <h1>Test</h1>
         <br>
         <form method="post" action="test.jsp">
         <table>
    	     <tr><td> 
    	     Username:
    	     </td><td>
    	     <input name="username" type="text" style="width:400;"/>
    	     </td></tr>
    	     
    	     <tr><td> 
    	     Filename:
    	     </td><td>
    	     <input name="filename" type="file" style="width:400;"/>
    	     </td></tr>
    	
    	     <tr><td> 
    	     &nbsp;
    	     </td><td>
    	     <input name="submit" type="submit" value="Submit"/>
    	     </td></tr>
    	
    	     <tr><td> 
    	     &nbsp;
    	     </td><td>
    	     &nbsp;
    	     </td></tr>
    	
    	     <tr><td> 
    	     Parameters:
    	     </td><td>
    	     username=<%=userName%>, filename=<%=fileName%> 
    	     </td></tr>
         </table>
         </body>
         </html>

    Comment

    Working...