Java/C# code example

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nicholas Potts

    #1

    Java/C# code example

    Hi, I'm trying to findout the equivalent code in C# for the following
    Java example that extracts information from an HTTP request header.


    import java.io.*;
    import javax.servlet.* ;
    import javax.servlet.h ttp.*;

    public class BasicServlet extends HttpServlet {
    throws IOException {

    PrintWriter out = res.getWriter() ;

    out.println("<h tml>");
    out.println("<b ody>");
    out.println("<p >");

    String name = req.getParamete r("name");
    if (name != null)
    out.println("He llo" + name);
    else
    out.println("He llo anonomous user");

    out.println("</p>");
    out.println("</body>");
    out.println("</html>");


    can anyone help?
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Java/C# code example

    Nicholas,

    The Java Servlet model and the ASP.NET model are different, to say the least. In ASP.NET, what you want to go is get the HttpRequest instance that corresponds to the request. You can then use the QueryString property to get the values in the query string that were sent to to the server.

    To get the request (from anywhere), you can use the static Current property on the HttpContext class to get the current context. From there, you can use the Request property to get the request.

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - nick(d0t)paldin o=At-exisconsulting' dot|com

    On 6 Oct 2003 04:42:42 -0700, Nicholas Potts <Nicholas.Potts @btopenworld.co m> wrote:
    [color=blue]
    > Hi, I'm trying to findout the equivalent code in C# for the following
    > Java example that extracts information from an HTTP request header.
    >
    >
    > import java.io.*;
    > import javax.servlet.* ;
    > import javax.servlet.h ttp.*;
    >
    > public class BasicServlet extends HttpServlet {
    > throws IOException {
    >
    > PrintWriter out = res.getWriter() ;
    >
    > out.println("<h tml>");
    > out.println("<b ody>");
    > out.println("<p >");
    >
    > String name = req.getParamete r("name");
    > if (name != null)
    > out.println("He llo" + name);
    > else
    > out.println("He llo anonomous user");
    >
    > out.println("</p>");
    > out.println("</body>");
    > out.println("</html>");
    >
    >
    > can anyone help?[/color]


    Comment

    Working...