ServletInputStream in Servlet Forwarding empty

Please help me, i think i have a problem.
After reading and checking "request"
seem that the xml message soap included in "request" disappear.
I have to forwarding it to another servlet.
Is too late? I have lost it?
Where is it ?
I use the RequestDispatcher.forward() method for forwarding
but (i'm sure) the second servlet receives the "request.getInputStream()" empty.
Who can help me?
Thanks in advance
my code :
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletInputStream in = request.getInputStream();
byte[] fre=null;
String xml="";     
while (in.available()>0) {
try {
fre = new byte[in.available()];
in.read(fre);
xml = xml + new String(fre);
} catch (Exception exc) {
exc.printStackTrace();
if (ckeck(xml)) {     
request.getRequestDispatcher("myservlet2").forward(request,response);
}

You have already read the input stream. Once read, and it gets read, it can not be re-read. If you want the information in both places, read it in the first servlet and store it in a scope that the other servlet can read (like as a request attribute:
  byte[] fre=null;
  String xml="";
  while (in.available()>0) {
    try {
      fre = new byte[in.available()];
      in.read(fre);
      xml = xml + new String(fre);
    } catch (Exception exc) {
      exc.printStackTrace();
  request.setAttribute("xml", xml);
  if (ckeck(xml)) {
    request.getRequestDispatcher("myservlet2").forward(request,response);
//... then in myservlet2
  String xml = (String)request.getAttribute("xml");

Similar Messages

  • Javax.servlet.forward.request_uri request attribute

    Hi,
    I have declared a security-constraint on my web application, which redirects to a page with a form.
    I want to know the initial request. It usually can be retrieved in the javax.servlet.forward.request_uri request attribute, so by doing
    request.getAttribute("javax.servlet.forward.request_uri")
    But this always returns me null.
    If I test the same thing on Tomcat, it works fine.
    This attribute come with Servlet 2.4, and Weblogic 11g is JEE 5 compliant (so Servlet 2.5). So it should work.
    Is there a particularity for Weblogic ?
    Regards

    >
    This attribute come with Servlet 2.4, and Weblogic 11g is JEE 5 compliant (so Servlet 2.5). So it should work.
    Is there a particularity for Weblogic ?This attribute does exist and has to be filled when a forward is done. However there's no strict requirement that the j_security_check is handled internally by a forward. If it's not, then that request attribute wouldn't come into play.
    I've never used it, so caveat emptor, but there is a public class we have which does appear to have some methods that may be helpful to you.
    http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e13941/weblogic/servlet/security/ServletAuthentication.html
    ServletAuthentication allows both form-based authentication and programmatic authentication in servlets. It performs the authentication call through the Realm and sets the user information into the session.And the static getTargetURLFromFormAuthentication method:
    http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e13941/weblogic/servlet/security/ServletAuthentication.html#getTargetURLForFormAuthentication(HttpSession)
    -steve-

  • Servlet forward problem

    Hi
    I have a servlet which is forwarded to JSP file.The JSP got content type as XML.But it gives error like "System cannot understand the specified encoding".but when i takeout the content type its works fine.
    can anyone give some ideas pls?

    Hi
    I am getting the following error
    System does not support the specified encoding. Error processing resource
    from servlet i am doing following
    res.setContentType("text/xml");
              RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/test/STWDesign/View.jsp");
    where in the view.jsp i am displaying xml data.
    thanks for you help
    waiting for reply.

  • Servlet to servlet forwarding

    Hello.
    I am writing a small controlling servlet to check certain request parameters before forwarding the request to the appropriate page.
    The controlling servlet is mapped to "/*" under the application so that all requests will hit it first.
    This is how I forward the request.
    Code to check paramaters and decde url
    RequestDispatcher rd = getServletConfig().getServletContext().getRequestDispatcher("/location/file.jspx");
    rd.forward(request,response);
    My problem is that this seems to send the browser into an infinite waiting loop when I type "http://localhost/application/".
    Is this the right way to do it? Any other techniques or suggestions.
    Thanks
    Sawan

    when you type http://localhost/application nothing happens
    now
    when you type http://localhost/application/anything
    you get to the controlling servlet
    The error you are getting in caused by the controller servlet
    does the resource http://localhost/application/location/file.jspx exist
    and whats with the x.

  • Servlet forward proxy

    Hi all.
    I'm trying to build a servlet which will act as a proxy between another system written in C++ and my J2EE applications. A browser client will go through the C++ app. down to my proxy.
    Basically I want my proxy servlet to receive a HTTP POST, strip out some header data and re-POST the data to another servlet. The response will the travel the same way back through the proxy up to the C++ app.
    The problem is that my proxy servlet and my J2EE applications won't be running on the same machine. Therefore I can't use the nice RequestDispatcher to forward to my other servlets or include them.
    So, what to do?
    I guess it's possible to collect data from my HttpServletRequest object in the proxy servlet and create a new POST and then write it on an outputStream to my other servlet. But is this the only way?
    It's really important that my application receives a POST that looks the same as the one reaching the proxy.
    I hope someone can give me a hint.
    regards
    Fredrik

    Have your proxy servlet open a HttpURLConnection to the second servlet and use this connection to do the post.
    Should work but I have never done it from a servlet.

  • Unread Email in gmail cannot read unless clicking on reply or forward, empty page.

    When you click on the unread email there's ONLY an empty box with reply or forward, no email body.

    ''GMail entire message content missing (blank) after header title''
    In Firefox, if you have "Adblock Plus" extension.
    # "Ctrl+Shift+F" Preferences (or right click on ADP symbol, and choose preferences)
    # 'Filters' menu > "'''Update all subscriptions'''"
    reference: ''https://support.mozilla.com/questions/896267''

  • Servlet forward not working with portal and oc4j

    Scenario: page1.jsp, page2.jsp, MyServlet
    Page1.jsp posts a form to MyServlet which then does some processing and forwards to page2.jsp.
    Tests:
    Works fine as a standalone app under oc4j.
    Does not work as oc4j-driven portlet under latest portal. Specifically, it conks out on the forward.
    Question:
    Why?
    What is the suggested workaround?
    Michael Mogley
    Software Engineer
    LRN, Inc.

    James, thanks for responding but you are misunderstanding the problem. I have been able to do multipage and form-submit portlets as you describe for a long time. The issue is I am not able to use the jsp-forward directive within a validation servlet when using oc4j with portal. Here is what I'm trying to do in pseudocode:
    EntryPoint.jsp
    1. Enter form data.
    2. Submit form to MyServlet.
    MyServlet
    1. Validate form.
    2. If valid, <jsp-forward page="success.jsp"/>.
    3. Else, <jsp-forward page="failure.jsp"/>.
    The above works fine when used in an app running on oc4j outside of portal. It does not work when the same oc4j app is portletized. By the way, the portletized app WILL work if I change jsp-forward to jsp-include. So the problem is obviously in the forwarding.
    Michael
    I would try looking at the samples in the PDK-Java V2 that show how to do form input and multipage behavior. The form input shows you how to make a form in a portlet that when you submit it, the entered values appear in the portlet. The multipage portlet shows you how to have a portlet display one page and then when you click on a link, it shows you the second page.
    It may make sense to copy the same code used for the samples and just tweak it to create a form that passes values from page1 to page2.
    For more info on V2 parameters, see the article "A Primer on Parameters and Events" in the PDK-Previews (for subscribers to Developer Services only). You can also see the V1 article called "Understanding the Parameter Passing Portlet" for more info on parameter passing with portlets in V1.
    James
    James

  • Servlet Forward + Connection reset by peer

    I have a strange error when making a forward from a servlet to a JSP page that exists !
    i have the following message :
    Connection reset by peer: socket write error
    If i use Mozilla to access the same page, it works fine !!!
    Strange !
    Can you help me please ?

    I use OC4J 9.0.4 and had the same error in IE6 but everything works fine in IE5 ! The same application works fine in JBOSS with both versions of IE (5 and 6).

  • How to detect servlet forwarding problem?

    Hi all experts,
    I have a servlet that forward (using forward method in request dispatcher) the requests to a certain destination URL.
    But if that URL is down or not found (like 500 or 404), forward method will not throw exception.
    But how do I get the response code in this forwarding? Interpret the response header from output stream of response object? I did not found any related methods in java that can simply allow us to get the response code (only allow us to set but not get).
    Thanks a lot!

    If you are using JBOSS or other application servers in that web.xml of your application just write
    <error-page>
    <error-code>404</error-code>
    <location>Error.jsp</location>
    </error-page>then it will be taken care of by container

  • Servlet Forwarding

    After forwarding control to another JSP page or servlet using the RequestDispatcher.forward() method, can the response be modified once the forward method returns? For example,
    RequestDispatcher rd = request.getRequestDispatcher("/somepath");
    rd.forward(request, response);
    response.getWriter().println("Some more output");

    do you mean send the forward and then update the response in the one servlet jsp?
    If so answer is NO
    You can add parameters to the request and add them to the response in the forwarded
    servlet/jsp if that is any help
    servlet_jsp 1:
    request.setAttribute("somemorestuff","more stuff more stuff");
    RequestDispatcher rd = request.getRequestDispatcher("/servlet_jsp2");
    rd.forward(request, response);
    servlet_jsp2:
    String ex = (String)request.getAttribute("somemorestuff");
    response.getWriter().println(ex);

  • Servlet forward request

    In 5.6 do you know how I can forward a request within a servlet that contains query string parameters.
    This does not work:
    RequestDispatcher rd = request.getRequestDispatcher("/content/geometrixx/en?message=Test");
    rd.forward(request, response);

    See discussion here: http://sling.markmail.org/thread/6b3e3sxe2c6plkcj

  • Iplanet/Servlet Forwarding Issue/Question

    Scenario:
    A directory is protected using Iplanet web server access control (Iplanet Directory Server). User accesses the directory and enters valid user name and password. User is authenticated OK. The file is then posted to a servlet which does a forward to another page in the same directory. The page is not displayed due to a problem with authentication. Code to forward is as follows:
    getServletConfig().getServletContext().getRequestDispatcher(response.encodeURL(pageName)).forward(request,response);
    I check request.getUserPrincipal().getName() and
    request.getRemoteUser(). The first returns the username that iWS is running under, the second returns
    null. Is there a correct way of doing this to avoid the forward from failing.

    requiem wrote:
    Question to BT
    Hello i have recently joined BT Infinity and have hit the issue of the Port Forwarding not working. My HH3 is on the following version of software. Will this version automatically upgrade to the latest version of firmware and will this fix my port forwarding issue?.........
    Thank you
    Dean.
    Current firmware:
    V100R001C01B031SP09_L_B
    Last updated:
    Unknown
    Hi Dean
    By the look of it you've got the type B version of the HH3 with current firmware.
    From http://bt.custhelp.com/app/answers/detail/a_id/13073
    The latest versions of the firmware are:
    BT Home Hub 3 – Software version 4.7.5.1.83.8.57.1.3 (Type A) or V100R001C01B031SP09_L_B
    Please Click On any Text in Blue as that automatically links to information.
    PC (NDEGR)

  • Javax.servlet.forward.request_uri

    Hi!
    I'm trying to track down reasons why I'm getting unexpected results for:
    HttpServletReqeust.getRequestURI()
    The results are different on Sun 7.0.3 compared with Jetty and Tomcat.
    Todd

    web server error log stack trace should point you with enough information as to why the behavior is different. also, if you are going to be developing with 7.0 , you could check out this feature -
    http://blogs.sun.com/kmeduri/entry/exception_stack_instead_of_server
    af course, if you can share a sample code which shows the change in behavior , we will be happy to chime in appropriately

  • Clarification of Servlet Spec for forwarding and filters

    Hi everybody,
    I'm having a problem trying to use SiteMesh in WebLogic 9.1 vs Tomcat 5.5.17. The issue seems to come up because the two containers have different behavior when it comes to forwarding and filters.
    The scenario is this: A request comes in to a servlet, that servlet forwards to a JSP page using RequestDispatcher.forward(). The SiteMesh filter looks at request.getServletPath() after the chain has executed and determines whether or not to apply the decoration based on the path of the page. The filter's doFilter() method looks something like :
    chain.doFilter(request, response)
    if(request.getServletPath() = matchingPath)
        applyDecoration();
    }Now, in Tomcat, a call to request.getServletPath() before and after the call to chain.doFilter() returns the exact same thing, regardless of whether the target servlet executes a forward. But in WebLogic, the call to getServletPath() after chain.doFilter() returns the forwarded path, not the original path.
    Who is right? Or is this one of those gray areas?
    Thanks,
    Scott

    Thanks for the info. You are correct, I was using 'forward'. I changed it to use 'sendRedirect' and this time the request goes via the filter. However, the request parameters that were in the original request have disappeared after the 'sendRedirect'. I could just add all the request parameters to the string I pass to sendredirect but was wondering if there was a better/simpler way.
    Thanks,
    Paul

  • Need help trying to figure this problem out.  Username validate on servlet.

    Hello.
    Here is my dilema. Almost everything works but the username check servlet.
    I have form that gathers information that sends to a bean to validate the forms fields. If the fields check out ok it than forwards to Vusername servlet which checks the username in the database to make sure there is not one of the same username in there. If there is the servlet redirects to a retry page notifying the user that the username is already taken. If successfull the servlet forwards to another servlet which processes all the registration information into the database.
    As i said everything works fine but the Vusername servlet. I dont think the problem is with my sql query which checks for an exsiting username with the one that was entered into the form.
    I think the problem is with my if statements. I think they are currently checking if the sql query has ran. If true do this if false do that. Which is not right.
    I need the if statments to check against the result of the sql query being true or false and than redirect depending on those variables.
    Anyway any insight would be greatly appreciated.
    Here is a copy of the Vusername servlet.
    Thanks.
    // Andy Janow
    // 03/01/05
    // Make sure the username is available.
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import Sql;
    public class Vusername extends Sql
    public void doPost( HttpServletRequest req, HttpServletResponse res )
    throws ServletException, IOException
         String user;
         String pass1;
         String pass2;
         String email;
         String sError = "/Error.jsp";
         String Failure = "You need to retry";
         String fUsername = "/usernameError.jsp";
         String fUserOb = "Username is in use already";
         // Get the username from the bean.
      user = req.getParameter("userName");
      pass1 = req.getParameter("password1");
      pass2 = req.getParameter("password2");
      email = req.getParameter("emailAddress");
      // Creating the string to check available username.  
      boolean isTaken = isUserNameTaken(user);
      // Creating the forward on error due to unavailable username selection.
       if (isTaken = true);
        req.setAttribute("fUserOb",fUserOb);
           RequestDispatcher rd = getServletContext().getRequestDispatcher(fUsername);
           rd.forward(req, res);
      // Creating the forward on Error page.
       if (isTaken = false);
        req.setAttribute("Failure", Failure);
           RequestDispatcher rd = getServletContext().getRequestDispatcher(sError);
           rd.include(req, res);
    // Sql QUERY for username.
    public boolean isUserNameTaken(String username)
        boolean isTaken = false;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try
            ps = connection.prepareStatement("SELECT userName FROM Registration WHERE userName = ?");
            ps.setString(1,username);
            rs = ps.executeQuery();
            isTaken = rs.next(); // returns true if there is a row returned
        catch (SQLException e)
            e.printStackTrace();
        finally
        { // ALWAYS clean up your resources
            try
                if (rs != null) rs.close();
            } catch (SQLException e) { /* close quietly */ }
            try
                if (ps != null) ps.close();
            } catch (SQLException e) { /* close quietly */ }
        return isTaken;
    public void destroy()
      try
       connection.close(); // Closing the db connection (cleanup).
      catch( Exception e )
       System.err.println( "Problem closing the database" );
    }

    Thanks for the repli.
    I forgot to come back here and fix the topic to issue solved.
    In the past hour sience i posted i was able to work through and fix the problem.
    Was with my if statment... Just an error of typing to fast i suppose and not really going through my code very thouroughly.
    Think how i had the code posted i was using the
    if statment to check if the sql statement was true , than another if statment to check if was false..
    Thing is, is that i already was checking if the username was in the database or not in the actual sql statment block by assinging weather the it was (true) or it was not (false) to the resultset variable.
    So in my if statments higher up in the code i just needed to reformat them correctly, from if true do this, and if false do this... To if some variable is present do this, else do this.
    And now it works great.
    Just in case anyone was wondering.
    But thanks for the repli and interest :)

Maybe you are looking for

  • Logical System is not appearing in Informer tab to check SOD's

    Hi GRC Experts, I have an issue with logical system to run risk analysis. I created logical system by following the Config guide, added physical system and generated rules (RAR Configuration>>Logical Systems>>Generate Rule) for that logical system. I

  • I lost my LR cc when computer was crashed,

    got my PS back but now want the LR too. I pay for the CC already, $9.99/mo. How?

  • Validate input value against database

    Is it possible to check the value of an input field (regular input, not cfinput) against a database to check for duplicate values?

  • Error with Quicktime- PLEASE HELP

    I have been trying to figure this out forever. Nothing has worked. I want to download itunes, but my computer won't let me because it won't accept Quicktime, which is needed for itunes to function. I get an error message and all it says is to contact

  • Command line equivalent of Work Group Manager's export feature

    Hello everyone, I am have a hard time upgrading from Lion Server to Mountain Lion Server, especially with Open Directory. What I wish to do, is to import the existing users and groups of an existing server running Lion Server into a new (fresh) Open