Getting Parameters in a Servlet

I can�t get the parameters of the doPost method of a Servlet, here is the code of the servlet called FileEvaluation:
     public void doPost(HttpServletRequest req, HttpServletResponse resp)
          throws ServletException, IOException {
          String fileName = "";
          String action = "";
          String tipoarch = null;
          InputStream fileIn = req.getInputStream();
          Enumeration params = req.getParameterNames();
          FileEvaluationLogic flogic = new FileEvaluationLogic("1");
          tipoarch = req.getParameter("tipoarch");
          System.out.println("tipoarch: "+tipoarch);
          if (tipoarch != null){
               FileScanner scanner = new FileScanner(fileIn, tipoarch);
               scanner.verify();
and this is the Html that calls it:
<form name="form1" method="post" action="FileEvaluation" ENCTYPE="multipart/form-data">
<table width="75%" border="0" align="center">
<tr>
<td width="27%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><div align="right">Tipo de Archivo</div></font></td>
<td width="73%">
<select name="tipoarch" id="tipoarch">
<option value="1">CLIENTES</option>
<option value="2">PRESTAMO</option>
</select>
so, the variable tipoarch does not brings anything, anyone knows the reason?
Thanks.

Assuming, you're not trying to use a multipart form and that your html is correctly formatted,
this should work :
if ("a".equals.req.getParameter("name"))
out.println("filter success");
The key is that you never ever try to test equality between object using '==', because '==' is a reference test, not a equality test (you can have 2 strings that contains "a", they are equals but have different reference (two different physical objects).
One other interesting thing, is that you'd better test if "a" is equal to your parameter rather than the reverse. Note that, this way, you can spare the check on wether req.getParameter returns a null value.
For a global debugging code support help, insert the following code when you need to see what's coming in your request as parameters :
Enumeration e=req.getParameterNames();
while (e.hasMoreElements()) {
   String key=(String) e.nextElement();
   System.err.println("Request content : {"+key+"} => ["+req.geteParameter(key)+"]");

Similar Messages

  • Getting parameters from text and file input tag. .  canyou help me ?

    Hello!
    Is there anyway of getting parameters from an
    text field input in a form like :
    <form name="signinForm" method="post" action="uploadFile.jsp" enctype="multipart/form-data" >Actually I would like to insert the parameters and make the upload of an file
    on the same form. It is something likethis :
    Form.jsp
    <form name="signinForm" method="post" action="uploadFile.jsp" enctype="multipart/form-data" >   
    <input type="text" id="name" name="signinName" />
    <input name="signinFile" id="fileUp" type="file" />   
    <input type="submit" id="submit_btn" name="signinSubmit"/>uploadingFile.jsp
    <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
    <%@ page import="java.io.FileWriter,java.io.IOException" %>
    <%
    .//upload the file
    String email = request.getParameter("signinName").trim(); //this line is bringing me an NullPointerException
    %>Thanks in advance for any suggestion!!
    All the best!

    You cannot use the HttpServletRequest object to retrieve parameters from a multipart form. You'll have to use a package that can parse such a form. I suggest Apache commons FileUpload.
    http://jakarta.apache.org/commons/fileupload/
    Using this package you can get both the file upload and any other parameters.

  • How to get the data in servlet if the request encryption type is multipart/

    I am uploading files to the server.
    at that time,before upload ,I need to validate the upload file names.
    so,i am trying to get the value of those files names using
    request.getParameter("jobsheet"); in servlet.
    its giving null insted of file path.
    how to retrieve the the values of parameters if the request is multipart/form-data.
    any help please...

    I think that package works in struts framework right?
    If wrong ,correct me.
    actually I am following MVC pattern.not using struts.
    If this works even in normal web application also.then ok.
    But,Just I am looking how to get the values of jsp parameters
    I have 5 elements in jsp .
    below code:
    <form name="FileUpload" action="./UploadServlet" method="post" enctype="multipart/form-data">
    country <input type="text" name="country" value="">
    year <input type="text" name="year" value="">
    month <input type="text" name="month" value="">
    File<input type="file" name="file1" value="">
    <input type="submit">
    </form>
    I am trying to get the data in servlet like
    String country=req.getParameter("country");
    its getting null.
    I don't know how to get the values if the enctype is "enctype="multipart/form-data"
    If any one knows ,Please suggest me.

  • How to convert get parameters to post

    hi,
    i have a problem in adding parameters to url
    it is not executing all the parameters as the length is too long
    so i read in help file that if lenght is too long we need to convert get parameters to post
    can any one tell me how to do that its urgent
    http://sapwin2.agi.com:50000/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.pct!2fplatform_add_ons!2fcom.sap.ip.bi!2fiViews!2fcom.sap.ip.bi.bex?TEMPLATE=y_test_w001_q&BI_COMMAND_1-BI_COMMAND_TYPE=SET_ITEM_PARAMETERS&BI_COMMAND_1-VISIBILITY=HIDDEN&BI_COMMAND_1-TARGET_ITEM_REF=ANALYSIS_ITEM_1
    please tell me how to convert to post parameters

    Hi,
    in standard HTML post and get are the two methods sending data from one page to another. While method get the parameter to the URL after "?" and seperated by "&" method post is using an HTML-form.
    In your case I would suggest to implement a form with hidden fields named by your parameters and containing the values. By clicking the submit button, the hidden fields are transmitted as post parameters.
    example
    <html>
    <head> </head>
    <body>
    <form name="test" action="http://sapwin2.agi.com:50000/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.pct!2fplatform_add_ons!2fcom.sap.ip.bi!2fiViews!2fcom.sap.ip.bi.bex">
    <input type="hidden" name="TEMPLATE" value="y_test_w001_q">
    <input type="hidden" name="BI_COMMAND_1-BI_COMMAND_TYPE" value="SET_ITEM_PARAMETERS">
    <input type="hidden" name="BI_COMMAND_1-VISIBILITY" value="HIDDEN">
    <input type="hidden" name="BI_COMMAND_1-TARGET_ITEM_REF" value="ANALYSIS_ITEM_1">
    <input type="submit>
    </form>
    <body>
    </html>
    Hope this helps.
    Regards Michael

  • Can't define init parameters for multiple servlets

    I want to define init parameters for two servlets in the web.xml file but i only get null for my Login servlet
    <web-app>
    <servlet>
    <servlet-name>
    RSServlet
    </servlet-name>
    <servlet-class>
    RoadSafe.Servlet.RSServlet
    </servlet-class>
    <init-param>
    <param-name>serverip</param-name>
    <param-value>localhost</param-value>
    </init-param>
         <load-on-startup>
              2
         </load-on-startup>
    </servlet>
         <servlet>
    <servlet-name>
    Login
    </servlet-name>
    <servlet-class>
    RoadSafe.AdMisc.Login
    </servlet-class>
    <init-param>
    <param-name>serverip2</param-name>
    <param-value>localhost</param-value>
    </init-param>
         <load-on-startup>
              1
         </load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>
    RSServlet
    </servlet-name>
    <url-pattern>
    /RSServlet
    </url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>
    Login
    </servlet-name>
    <url-pattern>
    /Login
    </url-pattern>
    </servlet-mapping>
    </web-app>

    In the code for you Login servlet, are you using the name "serverip2" to access the initial parameter ?
    Thats the name you have used in the web.xml file.

  • How to pass parameters/atrributes to Servlet from ALBPM

    HI Friends,
    I am invoking servlet from bpm using server configuration, i am able to invoke servlet, but not able to pass parameters dynamically,
    Also I like to receive response parameters/attributes from servlets?
    Can any body help me on this?
    Look forward for response.
    Cheers

    Some helpful Docs on the WebServer component for you:
    The WebServer component is used to send HTTP requests to an HTTP server and capture the responses. It supports HTTP methods GET and POST.
    The body of the HTTP response is available in the WebServer.response attribute (String).
    Note: This component is superseded by the Fuego.NetX.AdvancedWebServer component, which provides better performance and more functionality like support for proxies and for more HTTP methods (like PUT and DELETE).
    Example: Get Oracle's website home page and save it to a file.
    getFrom(WebServer, url : "http://oracle.com", args : null)
    binaryResponse = Binary(text: WebServer.response,
    encoding: "UTF8")
    BinaryFile.writeFromBinaryTo(data : binaryResponse,
    name : "/tmp/oracle_index.html",
    append : false)

  • Problem !! How to upload an file and get parameters on the same form ?

    Hello!
    Is there anyway of getting parameters from an
    text field input in a form like :
    <form name="signinForm" method="post" action="uploadFile.jsp" enctype="multipart/form-data" >Actually I would like to insert the parameters and make the upload of an file
    on the same form. It is something likethis :
    Form.jsp
    <form name="signinForm" method="post" action="uploadFile.jsp" enctype="multipart/form-data" >   
    <input type="text" id="name" name="signinName" />
    <input name="signinFile" id="fileUp" type="file" />   
    <input type="submit" id="submit_btn" name="signinSubmit"/>uploadingFile.jsp
    <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
    <%@ page import="java.io.FileWriter,java.io.IOException" %>
    <%
    .//upload the file
    String email = request.getParameter("signinName").trim(); //this line is bringing me an NullPointerException
    %>Thanks in advance for any suggestion!!
    All the best!

    You can get the parameter value directly. You can do the following to get the parameter name.
    Directly take the request's input stream and parse the header and findout the value for text field.
    Or you can use apache's file upload utilities and do the following
    DiskFileItemFactory factory = new DiskFileItemFactory();
                   ServletFileUpload upload = new ServletFileUpload(factory);
                   List fileItems = upload.parseRequest(request);
                   Iterator iter = fileItems.iterator();
                   while (iter.hasNext()) {
                        FileItem item = (FileItem) iter.next();
                        if (item.isFormField()) {
         //Form data fields will be displayed here          out.println(item.getFieldName());
         out.println(item.getString());
    All the best..

  • Send Get request from a servlet.

    Is it possible to send parameters from one servlet to another by using get? I don't want to use Post because the servlet recieving the parameters already has the post method doing something else. Any ideas?

    May you can use the RequestDispatcher for your use.
    Doc:
    public interface RequestDispatcher
    Defines an object that receives requests from the
    client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server.
    The servlet container creates the RequestDispatcher
    object, which is used as a wrapper around a server
    resource located at a particular path or given by a
    particular name.
    This interface is intended to wrap servlets, but a
    servlet container can create RequestDispatcher objects
    to wrap any type of resource.
    It send the requset with the same methode to an other resource. You don't have care about the parameter.
    Your code could look like this:
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
            RequestDispatcher dispatcher = getServletConfig().getServletContext().getRequestDispatcher("/next");
            dispatcher.forward(request, response);
        }Dietmar

  • Using SET GET parameters in ITS

    Hi All,
    Is it possible to use set get parameters in ITS. We want to set some parameters in a BADI and read the value in ITS Template .
    Or is there any other method to do this?
    Thanks,
    Anubhav

    Sure. In your abap program use the following code
    *  ITS macros
    INCLUDE avwrtcxm.
    GET PARAMETER ID 'YOUR_PARAMETER' FIELD SAVE_PARAMETER.
    field-set u2018~YOUR_PARAMETERu2019 1 SAVE_PARAMETER.
    field-transport.
    in the template you can now use ~YOUR_PARAMETER.
    regards,
    Klaus
    Edited by: Klaus Layer on Feb 3, 2009 5:05 PM

  • Problem with SET GET parameters

    Hi all,
    I am facing a problem using SET and GET parameters.
    There is a Z transaction(Dialog program) where some fields of screen are having parameter ID's. That transaction is designed to diaplay/change status of only one inspection lot at a time.
    Now I need to call that transaction in a loop using BDC. I mean i need to update the status of multiple inspection lots(one after the other). Before calling the transaction I am using
    SET PARAMETER ID 'QLS' FIELD lv_prueflos.
    Unfortunately the transaction is only changing the first inspection lot. When I debugged I found that the screen field is changing in PAI. Even though in PBO it shows the next value, when it goes to PAI it is automatically changing to the first value(inspection lot).
    Example: Inspection Lots : 4100000234
                                               4100000235
                                              4100000236
    Now first time when the call transaction is being made the status of insp lot 4100000234 is changed. For the second time when insp lot 4100000235 is being passed in PBO ican see this. But the moment it enters PAI the screen field changes to 4100000234.
    Could you pls help me in solving this issue.
    Thanks,
    Aravind

    Hi,
    Problem with SET GET parameters
    Regarding on your query. Follow this below link.
    It will help you.
    Re: Problem with Set parameter ID
    Re: Problem in Set parameter ID
    I Hope it will helps to you.
    Regards,
    Sekhar

  • Report  using Set parameter & get parameters.

    Hi,
           My requirement is from select query  the list of PO will be display. Now i want when i click on one of the purchase order .
    i want to diaplay PO using CALL TRANSACTION 'ME23N'  with the help of set and get parameters .  or can i do it with interactive report.
    Regards,

    Hi,
    1) Write a Report to show the Output(Use HIDE statment for PO filed while outputing the list).
    2) In the event AT LINE-SELECTION write logic.
    GET CURSOR FIELD field VALUE val.
    SET PARAMETER ID 'BES' FIELD dobj.
    CALL TRANSACTION ME23N.
    Regards,
    J.

  • How to get javabean data in Servlets.( JavaBean -- Servlet(Controller)

    how to get javabean data in Servlets.
    1) I am using name ,password in Jsp(View )
    2) when I submit this Bean will be called and Setter methods will be called .
    3) In ServletController (controller) I want to get data of javabean.
    In this I have to do validation of user.
    I want to pass the javabean obj as like -->
    request.getAttribute("beanObj");
    My intention is to get all the poperties in javabean by passing bean id
    or beanobj ,
    Is there any way to get all the data using bean id or beanObj.
    Plz Reply,

    Now in the Servlet we can get the same bean by this code:
    PageContext pageContext = JspFactoryImpl.getDefaultFactory().getPageContext(this, request, response, null, true, 8192, true);
    UserBean userbean = (UserBean)pageContext.getAttribute("userbean", PageContext.SESSION_SCOPE);
    String userid = userbean.getUsername();
    For this code to work it is needed to import 2 files:
    import org.apache.jasper.runtime.JspFactoryImpl;
    import javax.servlet.jsp.PageContext;
    The JspFactoryImpl is in jasper-runtime.jar file provided in tomcat dir.It seems to me that you are exactly knowing what you are doing :-(
    You can get a Bean stored in a Session by
    request.getSession().getAttribute("userbean");
    In the login.jsp page for example we have the code
    <jsp:useBean id="userbean" scope="session"class="com.newproj.UserBean" />
    <jsp:setProperty name="userbean" property="*" />the jsp:setProperty is not called when you click on the submit button
    if fills the bean with the request values from the previous request.
    andi

  • How to use SET & GET Parameters in Module Pool

    Hi Friends,
    Can anyone please tell how to use SET / GET parameters and PARAMETER ID for a text box (Input / Output field ) in module pool? What is the purpose and where do we need to do coding for it?
    Note : I will definitely give the marks for good responses.
    Thanks in advance,
    Pradeep

    Hi Pradeep,
    You can save values in the SAP memory using a parameter ID. These
    are user and terminal-session specific, but available to all internal and
    external sessions.
    SET Parameter copies the corresponding field contents into the SAP
    System memory in the PAI processing block.
    GET Parameter copies the corresponding field contents from the SAP
    memory at the end of the PBO processing block, after data has been
    transferred from the program, if the screen field still has its initial value
    You can link an input/output field to an area of the SAP memory in the
    ABAP Dictionary.
    When you use an input/output field that is defined in the ABAP
    Dictionary, its parameter ID is displayed in the Dictionary attribute
    Parameter ID in the Screen Painter.
    Usage
    SET PARAMETER ID: ’CAR’ FIELD space,
    ’CON’ FIELD space,
    ’DAY’ FIELD space.
    Here is the link that explains the usage of GET/SET in detail
    <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9e0435c111d1829f0000e829fbfe/content.htm">http://help.sap.com/saphelp_erp2005vp/helpdata/en/9f/db9e0435c111d1829f0000e829fbfe/content.htm</a>
    Regards,
    Sharadha

  • How to run a project which gets parameters from a batch file

    Hello all,
    I use to run a program, which gets parameters only by interactive mode, using a batch file as you can see below:
    # myprogram < batchfile.txt
    Now, I'm updating its code by SunStudioExpress IDE and I'd like to run it from the batchfile. I have noticed that the project properties window has the option run -> arguments, however this program doesn't accept arguments this way and for changing it, I'd have a hard job.
    Does someone know how to run this project and to get its parameters from batchfile?
    Regards,
    Glauber

    Ah, it appears that when you run the project, "<" is passed as one of the arguments and is not treated as input redirection.
    Sorry, it looks like it is not possible to do the redirection; and it looks like a bug to me. Could you please file it through bugs.sun.com? It shouldn't take long as the problem is evident now.

  • JSF and GET parameters

    Hi,
    This might be an age old question - but I can't seem to find a nice elegant solution - is there any support in JSF for GET parameters? Are there any plans for this to be included? What can I do in the meantime?

    Use the #{param.name} syntax as the value of a property in your managed-bean declaration in the faces-config. Then load from the database in a @PostConstruct method. Then just reference the managed bean normally in your JSP/view. When the first reference occurs the implementation will instantiate the bean, set the property and invoke the @PostConstruct method.

Maybe you are looking for

  • Windows Vista not working correctly with Leopard 10.5

    I just updated my MacBook Pro 17" by installing Leopard 10.5xx (erased and installed), then used BootCamp to partition disk and install Windows Vista. In Windows, my volume control is on, but no sound. I just got the error, "This problem was caused b

  • Creation of view in a component

    Hi , may I have the step by step procedure  for the creation of view in a component. I have created the Enhancement set . then in BSP_WD_CMPWB I enter the component and say enhance it took me to the area where all views are in display mode and after

  • Is there a VI that reports the apparent radius of an image particle, in REAL pixels rather than INTEGER?

    We are looking at shapes that are nearly round. We are trying to calculate their volume. If we capture the image, and then look at the binary version, and then ask for the equivalent diameter or radius, we get a value in pixels which is integer. This

  • Trouble Saving in PSD format

    When I try to save an edited photo in PSD format, I end up with an unknown file and Elements 7 cannot open again. It is not JPG, or PDF so I cannot open it in any program. Can anyone help?  James Poling

  • Erratic Trackpad Issue - Very Annoying!

    I've got a MacBook Pro running Mac OS X 10.5.2. Ever since I upgraded to Leopard, I've had intermittent problems with my trackpad/cursor. Sometimes, after sleeping the computer and waking it up, I get very erratic cursor movements (it "jerks" around