0

I am creating a web application in Java and am having trouble retrieving a value from a text box. My aim is to ask the user to enter their email address and then use the value entered for the rest of my application. I do this by attempting to pass the value as part of the URL in the jsp file (and retrieve it using request.getParameter()). However, the value that I keep retrieving is null.

Here is my code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<HTML>
<HEAD>
<TITLE>Display file upload form to the user</TITLE>
</HEAD>

        <center>
                <label for="email">Enter email address</label>
                <input id="email" name="email">

        </center>

<% String mail = request.getParameter("email");
                        System.out.println(mail);%>
<BODY>
    <FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp?e=<%=mail%>" METHOD=POST>
        <br> <br> <br>

        <center>
            <table border="0" bgcolor=#ccFDDEE>
                <tr>
                    <center>
                        <td colspan="2" align="center"><B>UPLOAD THE FILE</B>
                            <center></td> 
                </tr>
                <tr>
                    <td colspan="2" align="center"></td>
                </tr>
                <tr>
                    <td><b>Choose the WebEx File To Upload and Convert:</b></td>
                    <td><INPUT NAME="file" TYPE="file"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit"
                        value="Upload and Convert Recording"></td>
                </tr>
                <table>
                    </center>
                    </FORM>
</BODY>
</HTML>

I am trying to pass the mail value into the jsp file so that I can use it in my application

user3254893
  • 1,071
  • 2
  • 13
  • 14

4 Answers4

4

Put the following code between form tag.

<form ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
    <center>
            <label for="email">Enter email address</label>
            <input id="email" name="email">
    </center>
   -------
   -------
 </form>

on Server side write

String email=request.getParameter("email");

this will definitely solved your problem.

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
Mitul Maheshwari
  • 2,647
  • 4
  • 24
  • 38
1

you are requesting for upload.jsp?e=<%=mail%> where the parameter name is e and an other side you are getting the request.getParameter("email"); try this request.getParameter("e");or use this instead upload.jsp?email=<%=mail%> for request.getParameter("email");

Mohsin AR
  • 2,998
  • 2
  • 24
  • 36
0

you can try :

<form ....  ACTION="upload.jsp?e=${mail}" method="POST">

And send parameters :

request.setAttribute("mail", "mymail@abc.com");
sev7nx
  • 21
  • 3
0

As per my understanding you are sending both parameters and file to the server by specifying multipart/form-data as form encryption type. As per my knowledge in this mode, normal parameters except files are not available directly on server side. If you can use third party libraries in your application, you can use Apche Commons and Commons IO libraries. You can also use the example specified here commons file uploading to overcome your problem.

You can visit multipart/form-data structure for more details.