Newbie request.getParameter(String) issue

I'm having an issue setting a boolean value in a bean based off a string from request.getParameter(). I've created a small example to illustrate what I want to happen:
testForm.jsp:
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
    <title>testForm</title>
  </head>
  <body><form method="POST" action="testWork.jsp">
      <input type="hidden" name="hiddenTest" value="1"/>
      <input type="submit" name="submitTest" value="Submit"/>
    </form></body>
</html>testWork.jsp:
<jsp:useBean id="test" scope="session"
             class="thistestapp.testClass"/>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
    <title>testWork</title>
  </head>
  <body>
  <%
  out.print("<p>" + request.getParameter("hiddenTest") + "</p>" );
  // Great it's sending "1"
  test.setTestB(request.getParameter("hiddenTest"));
  //So when I set this in the bean I should get true
  out.print("<p>" + test.getTestB() + "</p>" ); 
  //False? Not nice!!
  test.setTestB("1");
  //Alright there must be an issue with my code in the bean, so hardcode a
  //"1" in.  I should still get false.
  out.print("<p>" + test.getTestB() + "</p>" );
  //True?? I hate you.
  %>
  </body>
</html>testClass.java:
package thistestapp;
public class testClass {
    private Boolean testB;
    public void setTestB(String testB) {
        if ( testB == "1"){
           this.testB = true;
        else{
           this.testB = false;
    public Boolean getTestB() {
        return testB;
}So, I want when the bean is sent a "1" from the form to set the bean value to true. I however can't get that to happen. I'm sure there's something I'm missing.
TIA.
Joe

? if ( testB == "1"){
Standard beginner's error. If you want to test if two strings contain the same text, use the equals() method. Like this:if ( testB.equals("1")){Your code tests whether the two sides of the == operator refer to the same object. It's possible and likely for two different strings to contain the same value, which is what you are really interested in.

Similar Messages

  • Losing info after a & on a String url = request.getParameter("refurl");

    Hi...
    Wnen I am passing information.... like this....
    http://127.0.0.1:8080/forumoracle/forum_login.jsp?refurl=http://127.0.0.1:8080/forumoracle/forum_view.jsp?catid=2&threadid=4
    I seem to be losing the information after the amperstand.. and not sure why..
    String url = request.getParameter("refurl");
    So when I print out the url string.. I only get this...
    http://127.0.0.1:8080/forumoracle/forum_view.jsp?catid=2

    You can't redirect to a new window from the server end
    you have to make the decision at the client when you
    click the link. All a web server does is receives a
    request, and sends back a response.
    The decision about where to display that response is
    up to the browser. (ie does it replace current
    content, put into a new window etc etc)
    You can use the target attribute on links and forms to
    specify it from your HTML page, but once the
    link/button is clicked you are committed.While this is all true for JSP that doesn't care about the UI, JavaScripting makes it possible to open new windows, but it is lacking in some respects for my use. I am facing two issues:
    a)how to give a URLEncoder.encode string to JavaScript's window.open() legibly, and
    b) how to close a window opened with a JavaScript after a download of a file
    In both instances, there is ergonomics.

  • String xmlfile = "C:\\xmldocs\\" +request.getParameter("sample1.xml");

    Hi All,
    I am getting the following error while executing the following line in my jsp...
    String xmlfile = "C:\\xmldocs\\" +request.getParameter("sample1.xml");
    error: ..........
    java.io.FileNotFoundException: C:\xmldocs\null (The system cannot find the file specified)...
    What could be the problem ?
    Please reply..
    Thanks
    Harish Pathak

    "sample1.xml" is not recognised as a parameter (for obvious reasons). It should probably look something like:
    String xmlfile = "C:\\xmldocs\\" +request.getParameter("filename");                                                                                                                                                                                                                                                                                                                                                                   

  • Null value in Session vars and request.getParameter

    We're migrating our application from iPlanet.
              Under iPlanet, when we looped through a resultset and set the values to
              session variables - it worked fine, even when a resultset value was null,
              but in WebLogic, I get the following error:
              java.lang.IllegalArgumentException: key/value is null
              Is there anyway to "turn this off" so it behaves like iPlanet?
              My second question is that we have many JSP's that check to see if a
              parameter is null in javascript:
              Here's the code:
              function onLoad() {
              document.form.elements[0].focus();
              // Check to see if the user is coming from a shortcut
              var imageName = "<%=request.getParameter("imageName")%>";
              if (imageName == "null") {
              selectTop("<%=select_image%>");
              } else {
              selectTop(imageName);
              <% if (tableIndex == 2) { %>
              loadShortcutIcon(13,100);
              <% } %>
              in iPlanet, when the parameter "imageName" is not in the URL, the javascript
              variable gets set to "null" - but in WebLogic, it is set to a blank string -
              "". Is there anyway to make this return null like iPlanet?
              Thanks,
              Matt
              

    Hi,
    the URL parameter is added just for the request to the page. When you press the command button then you issue a new request that does not have a URL parameter added. To work around this, you can use a PhaseListener that stores the URL request parameter in the session for later use
    Frank

  • Request.getParameter("") values: Are they null or ""?

    Hello:
    I have a web page that links up to a MYSQL database. I use JSP files to process the database queries from an HTML form. However, I am having an issue after moving the code from MYSQL 5.0 and JDK 1.5 to a machine with MYSQL 4.X and JDK 1.4.X
    I am enabling user to enter several pieces of search criteria that I, in turn, use to build the SQL syntax statement. And I test to see which HTML fields the user has entered something into so that the SQL only includes those where statements.
    I first had the following to process the individual search criteria into SQL where statements:
    String tester1 = request.getParameter("tester");
    String tester = "";
    if (tester1 != "") {
         tester += " tester like \"" + tester1 + "%\"" + " and ";
         } else {
    tester += "";
    so if the user enter "Tommy in the tester field as a search criterion this part of the SQL would be
    tester like Tommy%
    Then I build the select statment with only the where statements that the user is interested in (and provided search criteria on):
    String syntax = "Select * from database where ";
    String array[] = { tester, call_from, call_to, r_no, rec_no, date };
    for (int counter=0;counter<array.length;counter++){
              if (array[counter] != "") {
              syntax += array[counter];
    int a = 0;
    int b = (syntax.length() - 4);
    String syntax1 = syntax.substring(a, b);
    so the above would create
    Select * from database where tester like Tommy%
    This worked on the previous machine. However, it no longer works on the machine with the older apis. So I have tried everything to weed out the blank database fields so they are not factored in the query (if they are they return nothing as these fields are required to be entered into the database). I tried this:
    String tester1 = request.getParameter("tester");
    String tester = "";
    if ((tester1 != "") || (tester1 != null)){
         tester += " tester like \"" + tester1 + "%\"" + " and ";
         } else {
    tester += "#";
    . . . and then . . .
    String syntax = "Select * from database where ";
    String array[] = { tester, call_from, call_to, r_no, rec_no, date };
    for (int counter=0;counter<array.length;counter++){
              if (array[counter] != "#") {
              syntax += array[counter];
    int a = 0;
    int b = (syntax.length() - 4);
    String syntax1 = syntax.substring(a, b);
    But no matter what I try the query that gets sent to the database is as follows:
    Select * from qa_data where tester like "%" and called_from_1 = "" and call_to = "" and r_no = "" and rec_no = "" and (date >= "" and date <= "")
    So I am at a loss. It appears that I am not testing for the correct value that the browser is sending to my JSP file when a user does not enter a value in the field. What other than "" and null are there? I have tested for one or the other and both. I am at a loss now as to what to do. I am only concerned with IE6/7 and Firefox 1.5
    I output what the value being sent to the JSP file was and it was something like "The tester value is:". So, basically it isn't anything ("").
    Can anyone help me here?

    Rule #1 when comparing strings: use the equals() method, rather than == or !=
    You only use == when checking for null, or checking to see if it is the same object.
    if (tester1 == null || tester1.trim().equals("")){
      // value is null/empty/spaces only
    else {
      // a value is present
    }

  • Retriving only hidden parameters from request.getParameter

    Hi,
    I want to retrive only the hidden parameters from previous JSP page into current JSP page. The problem here is that my hidden parameters in privious page are dynamically generated (parameter names are decided based on values retrived from the database) and I cannot retrive them using "request.getParameter(<parametername>)"
    Can I find the parameter type (i.e. text box, text area, checkbox, radio or hidden) from the request.getParameter() or request.getParameterNames() methods? or is there any other way to find it.
    Thanks in advance for any help

    You can use the getParameterNames() or getParameterMap() methods from javax.servlet.ServletRequest to get all the parameters in the request. Even if they're dynamically generated, and you don't know the names in advance, these methods will ferret them out.
    getParameterMap() returns name String, values String [] pairs, so you'll have to work with String arrays to get the input out. It's got to be that way to accomodate checkboxes and other HTML form elements that can send more than one value for a given name.
    I prefer getParameterMap, because I don't like using Enumerations as much. - MOD

  • How to get Int value from request.getParameter()?

    Hi all,
    I have a integer value which is passed from one page to another page.
    i am geting this value in the next page using
    request.getParameter().
    Eg.
    Suppose value of "i" in page1 is 32, i pass this as hidden variable to next page.
    <input type="hidden" Value="<%=i%>" NAME="limit">
    in page2, i fethch this value to a variable by name "limit"
    String limit=request.getParameter("limit");
    but, since value stored in limit is int, i can't assign it to string.
    i can't use request.getParameter for int values.
    How to solve my problem.
    I know it is simple,
    Pls. help me
    Regards
    ASh
    String limit=request.getParameter("limit");

      String limitSTR = request.getParameter("limit");
      int limit = -1;
      if (limitSTR != null) limit = Integer.parseInt(limitSTR);

  • In JSP pages request.getParameter returns null

    There are two jsp's,the first JSP has 1 textbox inside the form tag.We input the values in the textbox and submit.
    Code :Ist jsp
    <BODY>
    <HEAD>
    function validate()
    document.add.submit();
    </HEAD>
    <FORM name="add" method="post" action=/dir/two.jsp" >
    <TABLE width="37%" border="0" align="center" class="c4f3">
    <TR>
    <TD class="c4">Rating</TD>
    <TD><input type=text name="rating"></TD?
    </TR>
    <TR>
    <TD align=center><INPUT type="button" name="submitadd" value="Submit" onClick="validate()" </TD>
    </TR>
    </TABLE>
    </FORM>
    </BODY>
    After the submit it goes to the 2nd JSP page .
    code:2nd Jsp
    <%
    String Rating=request.getParameter("rating");
    out.println(" Rating "+Rating);
    %>
    The 2nd JSP pages gets the values by request.getParameter.When I use method='post' in Ist JSP ,even if I enter values in the textbox, it prints null. But when I give method="get" , it prints the value.
    Pls let me know if there is any problem in the code or its the problem due to webserver configuration.Also suggest the solution to over come this problem.
    Thanks

    If I'am right you have misplaced the opening body-tag of your first jsp-page.
    The opening body-tag should follow after the closing head tag .
    The structure of your HTML-code should look like this:
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>

  • In Portal, request.getparameter return NULL (Sample Monthcalendar)

    I used the sample monthcalendar. When i used it without integrated in portal, i can change month by month with ">>" button.
    In the JSP File, there is a call to the P_CALDATE parameter
    String l_inputDate = request.getParameter("P_CALDATE"); // Input Date.
    When i put this JSP file as an URL Portlet, i can't navigate month by month. the function request.getParameter("P_CALDATE") return NULL, but in the URL i have the parameter:
    http://hddms220.cg63.fr/servlet/page?_pageid=54,58,56&_dad=portal30&_schema=PORTAL30&P_CALDATE=2002-05-01.
    Someone have an idea
    Thanks in advanced

    I have tested the sample with JSERV, and all works fine.
    But if i wan't use OC4J/ORION to display a portlet how can i do it.
    Thanks in advanced

  • Geting null vaules with request.getParameter().....

    Hello Experts,
    I am sending a data from one jsp page to another using java script (document.form.txtbx.value = myData), on same page I cheked and got the correct value but on the next page, I am getting null vaues. I am giving my code just check out and give me suggetions..
    On button click I am calling function jfun_submit(..,..,..,..)
    function jfun_submit(mhCd , scheme , dhCd , dhnm ,  total , grantNo , noOfBill  ,grossAmt , n_p , totAMT , dept , c_v , type , grossAmtQtr , addAmount , LOC , flagnext , neg_flg , neg_amt_alwd,tansend,appNosend,appDatesend , loc)
      var getLink =mhCd+"|"+scheme+"|"+dhCd+"|"+total+"|"+grantNo+"|"+noOfBill+"|"+grossAmt+"|"+n_p+"|"+totAMT+"|"+dept+"|"+ c_v+"|"+type+"|"+grossAmtQtr+"|"+addAmount+"|"+"Budget"+"|"+flagnext+"|"+neg_flg+"|"+neg_amt_alwd+"|"+loc+"&Tan="+tansend+"&AppNo="+appNosend+"&AppDate="+appDatesend;
    document.bill.getLink.value= "";
    document.bill.getLink.value = getLink;      //setting the value to the txtfield
    alert("After Set : "+document.bill.getLink.value);  //shows alert correctly.
    var url="BillSchemeCheckX.jsp
    document.bill.action=url;
    document.bill.method="POST";
    document.bill.submit();
    {code}
    and on next jsp page me writing following code
    {code}
    String getLink = request.getParameter("getLink");
    out.println("GetLink Value : "+getLink);
    {code}
    the result displying GetLink value : null
    Please help me out                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    What is the html for the formfield 'getLink'? I am guessing you have the id parameter set which makes this bit work 'document.bill.getLink.value = getLink;' but you dont have the name parameter set so your request.getParameter isnt working.

  • Submitting request.getParameter value on page submit

    I am getting the value from the request parameter as under
    <%
    String mod = request.getParameter("mod");
    %>
    Now i want this mod value to be submitted as page submits. For that i used:
    <h:inputHidden id="mod_field" value="" />
    Now the question is how to pass the above mod value using this hidden input? and secondly how to bind it with the property in the backing bean (say the name of my backing bean is bean.navigation) so that i can access and use the value.

    Hay this exception has again started showing me up.
    exception
    org.apache.jasper.JasperException: javax.servlet.jsp.JspException: javax.faces.FacesException: javax.faces.el.ReferenceSyntaxException: param.mod
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
    root cause
    javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.FacesException: javax.faces.el.ReferenceSyntaxException: param.mod
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
         org.apache.jsp.tsheetRcode_jsp._jspService(tsheetRcode_jsp.java:344)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
    root cause
    javax.faces.el.EvaluationException: javax.faces.FacesException: javax.faces.el.ReferenceSyntaxException: param.mod
         com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:206)
         com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)
         javax.faces.component.UIOutput.getValue(UIOutput.java:147)
         com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:670)
         com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:549)
         com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:525)
         com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:481)
         com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:430)
         javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:712)
         javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:616)
         javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:539)
         com.sun.faces.taglib.html_basic.SelectOneMenuTag.doEndTag(SelectOneMenuTag.java:505)
         org.apache.jsp.tsheetRcode_jsp._jspx_meth_h_selectOneMenu_0(tsheetRcode_jsp.java:449)
         org.apache.jsp.tsheetRcode_jsp._jspService(tsheetRcode_jsp.java:263)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

  • JSP request.getParameter bug

    i try the following code for receive Parameters from jsp.
    <% String name=request.getParameter("Name"); %>
    but when Name TextField(in HTML) is empty and i want to check
    for none empty field with (if) instruction with following code..
    if(name ==null ) //somecodes..
    this instruction not run and programs continue .

    It's not a bug.
    <%
    String name=request.getParameter("Name");
    if (name == null) {
      //what to do if parameter does not exist
      //e.g.: a checkbox not checked
    } else if (name.trim().equals("")) {
      //what to do if parameter exists but is 'empty'
      //e.g.: an text input field with no non-whitespace characters
      //NOTE: if you want leading and trailing spaces to be
      //      considered values, remove the .trim() from the condition
    } else {
      //there is a value.. do with it as you will
    %>

  • Jsp request.getparameter doesn't get querystring values

    We have recently deployed our jsp application which was running successfully on ias8i apache jserv into the 8.1.7 JVM and configured the mod_ose on the Oracle HTTP server every thing seems to be fine except the following case.
    Here we are accepting the userid,password from a jsp and submiting to the same jsp for action on submit we are reading a combination of jsp form feilds and url querystrings strangely we are able to get values only for the form feilds and querystrings return null.
    The same peice of code works fine on apache jserv implementation.
    Any clues please write to me.
    <SCRIPT Language="JavaScript">
    function check_password()
    document.Login.action ="problem.jsp?tab=YES&nSessionId="+document.Login.sessionid.value+"&nUserId=" + document.Login.userid.value;
    document.Login.target = "_top";
    document.Login.method = "post";
    document.Login.submit();
    </SCRIPT>
    <%
    userid = request.getParameter("userid");
    password = request.getParameter("password");
    tab = request.getParameter("tab");
    %>
    <form name="Login" Border="0" TopMargin="0" LeftMargin="0" Marginheight="0" Marginwidth="0">
    <table>
    <tr>
    <td class="FORMHEADERLEFTB"><b> Login</td>
    <td class="FORMHEADERLEFT">:</td>
    <td><input TYPE="TEXT" NAME="userid" SIZE="25" VALUE="<%=userid%> MAXLENGTH="10"></td>
    </tr>
    <tr>
    <td class="FORMHEADERLEFTB"> Password</td>
    <td class="FORMHEADERLEFT">:</td>
    <td><input TYPE="password" NAME="password" SIZE="25" VALUE="<%=password%>" MAXLENGTH="10" onChange="check_password()"></td>
    </tr>
    </table>
    <input type="hidden" name="sessionid" value="999999">
    </form>
    Thanks
    suresh
    null

    How are you retrieving the parameter values? I am able to retrieve parameters successfully using the following simple testcase:
    untitled1.jsp:
    <form method="post" action="servlet1">
    <P>Username:
    <input type="text" name="un"/>
    </P>
    <P>Password:
    <input type="text" name="pw"/></P>
    <P>
    <input type="submit" value="Submit"/>
    </P>
    </form>
    servlet1.java: (copy and paste from doGet() to doPost() method depending on value of form method in untitled1.jsp)
    String un = request.getParameter("un").toString();
    String pw = request.getParameter("pw").toString();
    out.println(un);
    out.println(pw);
    Please test this and let me know your results and the differences with what you are trying to do.
    Regards,
    Lynn
    Java Tools Team

  • Unable get complete filepath from jsp page using request.getParameter()

    Hey all,
    i am actually trying to get the selected file path value using request.getParameter into the servlet where i will read the (csv or txt) file but i dont get the full path but only the file name(test.txt) not the complete path(C:\\Temp\\test.txt) i selected in JSP page using browse file.
    Output :
    FILE NAME : TEST
    FILE PATH : test.txt
    Error : java.io.FileNotFoundException: test.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at java.io.FileReader.<init>(FileReader.java:55)
    at com.test.TestServlet.processRequest(TestServlet.java:39)
    at com.test.TestServlet.doPost(TestServlet.java:75)
    JSP CODE:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>DEMO SERVLET</title>
    </script>
    </head>
    <body>
    <h2>Hello World!</h2>
    <form name="myform" action="TestServlet" method="POST"
    FILE NAME : <input type="text" name="filename" value="" size="25" /><br><br>
    FILE SELECT : <input type="file" name="myfile" value="" width="25" /><br><br>
    <input type="submit" value="Submit" name="submit" />
    </form>
    </body>
    </html>
    Servlet Code :
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException, FileNotFoundException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
    String filename = request.getParameter("filename");
    out.println(filename);
    String filepath = request.getParameter("myfile");
    out.println(filepath);
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet TestServlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
    if (filepath != null) {
    File f = new File(filepath);
    BufferedReader br = new BufferedReader(new FileReader(f));
    String strLine;
    String[] tokens;
    while ((strLine = br.readLine()) != null) {
    tokens = strLine.split(",");
    for (int i = 0; i < tokens.length; i++) {
    out.println("<h1>Servlet TestServlet at " + tokens[i] + "</h1>");
    out.println("----------------");
    out.println("</body>");
    out.println("</html>");
    } finally {
    out.close();
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    Needed Output :
    FILE NAME : TEST
    FILE PATH : C:\\Temp\\test.txt
    Any suggestions Plz??

    As the [HTML specification|http://www.w3.org/TR/html401/interact/forms.html] states, you should be setting the enctype to multipart/form-data to be able to upload files to the server. In the server side, you need to process the multipart/form-data binary stream by parsing the HttpServletRequest#getInputStream(). It is a lot of work to get it to work flawlessly. There are 3rd party API's around which can do that for you, such as [Apache Commons FileUpload|http://commons.apache.org/fileupload] (carefully read the User Guide how to use it).
    You can also consider to use a Filter which makes use of the FileUpload API to preprocess the request so that you can continue writing the servlet code as usual. Here is an example: [http://balusc.blogspot.com/2007/11/multipartfilter.html].

  • In WL6.1 request.getParameter returns NULL for URL parameters that exist

              With the following URL, I get different results between WebLogic 4.5.1 and WebLogic
              6.1:
              http://phx-kmccarthy.medspecialists.net/tsweb/ParametersTest.jsp?apple=macintosh&tree&dog&country=USA
              Weblogic 6.1 returns:
              query string = apple=macintosh&tree&dog&country=USA
              apple = macintosh
              tree = null
              dog = null
              country = USA
              WebLogic 4.5.1 returns:
              query string = apple=macintosh&tree&dog&country=USA
              apple = macintosh
              tree =
              dog =
              country = USA
              here is the jsp...
              <%--
              * ParamtersTest.jsp which shows that empty parameters are ignored in WebLogic
              6.1
              --%>
              <%
              String apple, tree, dog, country;
              apple = request.getParameter("apple");
              tree = request.getParameter("tree");
              dog = request.getParameter("dog");
              country = request.getParameter("country");
              out.println("<br>query string = " + request.getQueryString());
              out.println("<br>apple = " + apple);
              out.println("<br>tree = " + tree);
              out.println("<br>dog = " + dog);
              out.println("<br>country = " + country);
              %>
              From the documentation on the getParameter() method:
              Returns the value of a request parameter as a String, or null if the parameter
              does not exist.
              In my opinion, not existing and being empty are different. Also, every other web
              application environment we've dealt with (including WebLogic 4.5.1) treats them
              as different. If the parameter doesn't have a value, (i.e. ...&tree&dog&...) then
              getParameter() returns the empty string, not null.
              As a result of this we have JSPs that break when running on 6.1.
              

    Found the solution at last. Tomcat servlet container can't handle the chunked transfer-encoding that the J2ME Wireless Toolkit uses when you call outputstream.flush() in midlet. Using outputstream.close() instead of outputstream.flush() will avoid this problem for small requests. For all the codes in the articles on Http Post in Wireless Forum, don't use outputstream.flush() and it will run perfectly - Servlet's request.getParameter(parameterName) will work fine in doPost method.

Maybe you are looking for