Help: No Parameters, HTML Output from Java Servlet

I have a Java Servlet that reads parameters passed from an HTML form and displays them to another HTML page. I know the servlet is being invoked; however, I am not seeing any HTML output. Sending the output to a file reveals the parameters are coming in as NULL as well.
I attempted a simple sample app with the same results. Here is what I am running:
The HTML Form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Collecting Three Parameters</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">Collecting Three Parameters</H1>
<FORM ACTION="ThreeParams">
First Parameter: <INPUT TYPE="TEXT" NAME="param1"><BR>
Second Parameter: <INPUT TYPE="TEXT" NAME="param2"><BR>
Third Parameter: <INPUT TYPE="TEXT" NAME="param3"><BR>
<CENTER><INPUT TYPE="SUBMIT"></CENTER>
</FORM>
</BODY>
</HTML>
The Java Code:
public class ThreeParams extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading Three Request Parameters";
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
     "Transitional//EN\">\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" +
"<UL>\n" +
" <LI><B>param1</B>: "
+ request.getParameter("param1") + "\n" +
" <LI><B>param2</B>: "
+ request.getParameter("param2") + "\n" +
" <LI><B>param3</B>: "
+ request.getParameter("param3") + "\n" +
"</UL>\n" +
"</BODY></HTML>");
What happens when I "submit" from the form is the same form reloads with the query string in the URL: "http://localhost:8080/ThreeParams/?param1=1&param2=2&param3=3"
Any assistance with either (or both) would be thoroughly appreciated:
a) why the parameters are not being passed correctly to the servlet
b) why the HTML output page is not displayed
Thanks in advance!
- Steve

I have found the answer to my problem listed in another thread.
Thank you.

Similar Messages

  • Return data from Java servlet in form of JSON encoded parameters in Javascr

    How to return data from Java servlet in form of JSON encoded parameters in Javascript handler function call?
    The same is implemented in php as the following
    echo "sT.handleAjaxResponse(";
    echo json_encode($response);
    echo ");";
    How to do the same in Java servlet?
    Thanks.

    With the rising popularity of JSON (especially with Ajax), support for it has started to appear in the Java community. I am not aware of any standardized approach yet, but expect it is likely we'll see that eventually. For now, you probably want to look at a third-party library such as the [JSON in Java Library|http://www.json.org/java/], Jettison, or [Java Tools for the JSON Format|http://jsontools.berlios.de/].

  • Get parameters from html page from java application standalone ...

    Hi all,
    I work in one solution that i have values in Html Page and i want get the parameters values from html and cath they in java application standalone.
    The Html page is in same host than de java application.
    I want know if this is possible. I wnat know if without HttpServlet i can get the parameters from Html Page pure.
    Thanks in Advance for the ideas,
    Antonio.

    Hi Abdul,
    The problem is my client want one solution where i have one page simple page Html and one application java standalone. This application runs in one machine, but we don't have web server. So the question is: Is possible without web server i can get the parameters values that is inside the html page from java application. I remember you that the application java is one .jar that run's with one command line from crontab "java -jar teste.jar".

  • Changing the HTML Target From a Servlet

    Is there any way to change the HTML TARGET when sending an HTML page from a servlet to a HttpServletResponse object?

    Of course it's the HttpServletResponse object, I'm sorry about that.
    The best resource for figuring out all the HTTP headers is reading the HTTP 1.1 Specification. This is available at:
    http://www.w3.org/Protocols/
    Look for the RFC 2616 link(s).
    However, some browsers have their own extensions to the HTTP 1.1 Spec. If you want to learn more about these, the best place to look is the browser's website.
    Finally, I'm sure there are some websites out on the web that exist soley to education us on HTTP headers. Find them at www.google.com searching for "HTTP headers".
    Good luck!

  • HTML output from Maven report

    Is there a way to get HTML output from the Maven report? When I do a site generation, I see pmd.xml in the target directory and a flexpmd.html file in target/site, but flexpmd.html is essentially empty. I don't see any configuration option for this. The "regular" PMD plugin always outputs HTML and the XML output is an option (although it defaults to on): http://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html#format

    Actually, flex-pmd-maven-plugin 1.0.RC4 understands this in the configuration tag:
         <outputDirectory>${project.build.directory}/site</outputDirectory>
         <targetDirectory>${project.build.directory}/site</targetDirectory>
    With this, "pmd.xml" and "flexpmd.html" are placed in the site folder, but "flexpmd.html" is replaced later with the empty site report template. So, no real gain here.
    Any ideas on how to integrate the "flexpmd.html" file with the site reports?

  • Get complete output from java.lang.Process

    How do I get the complete output from java.lang.Process?
    By the time I've started reading from Process.getInputStream() the process has already terminated...

    I solved the problem:
    private int exec(String pArguments[], OutputStream pOut, OutputStream pErr) throws IOException {
         class ProcessOutputPrinter implements Runnable {
              private InputStream ivIn;
              private OutputStream ivOut;
              public ProcessOutputPrinter(InputStream pIn, OutputStream pOut) {
                   ivIn = pIn;
                   ivOut = pOut;
              public void run() {
                   try {
                        for(int tByte; (tByte = ivIn.read()) != -1; ) {
                             ivOut.write(tByte);
                        ivOut.flush();
                   catch(IOException e) {
                        e.printStackTrace();
         // Start process
         Process tProcess = Runtime.getRuntime().exec(pArguments);
         // Create out printer
         Thread tOutPrinter = new Thread(new ProcessOutputPrinter(tProcess.getInputStream(), pOut), "NamingAdmin out-printer");
         tOutPrinter.start();
         // Create err printer
         Thread tErrPrinter = new Thread(new ProcessOutputPrinter(tProcess.getErrorStream(), pErr), "NamingAdmin err-printer");
         tErrPrinter.start();
         // Wait for process and printers to finish
         try {
              tProcess.waitFor();
              tOutPrinter.join();
              tErrPrinter.join();
         catch(InterruptedException e) {
         // return process exit value
         return tProcess.exitValue();

  • How to Call SQL Loader from Java ( servlet )?

    We need to call SQL Loader command from Java Servlets? Any suggestions how this can be done?
    Thanks
    Rahul

    Probably not the best way, but you could try using JNI to call a C function which then invokes SQL Loader via system() or exec(). I haven't done this myself though...

  • Calling XSQL from java servlet

    I'm able to call XSQL, process the page, and display it. But, how do I set the stylesheet from within my java servlet.
    I tried params.put( "xml-stylesheet", "[path to sheet]" ), and then passing that to process(), but it just ignores it. I want to be able to set the stylesheet dynamicaly like when you call XSQL from the command line or from the XSQL servlet.
    XSQLRequest req = new XSQLRequest( xsql );
    Hashtable params = new Hashtable(2);
    params.put( "mths", "6");
    params.put( "run_id", "30");
    params.put( "grade", "A" );
    params.put( "xml-stylesheet", xsl ); <-- just seems to ignore this.
    ByteArrayOutputStream ostr = new ByteArrayOutputStream(2048);
    req.process( params, ostr, new PrintWriter(System.err) );

    Thanks for the help Steve (and thanks for a really nice book by the way.)
    To answer your first question, I have implemented a report caching servlet. In the application we're writing, reports are generated in HTML or PDF (using XSQL) on demand. However, the data really only changes once a day at most so I wanted to have a way to store the reports once they were generated. So this servlet basically gets the request for a report, checks to see if the report has already been generated and, if not, generates the report using XSQLRequest. Finally it returns the report to the user.
    One benefit to doing this is that it masks the generation process from the user (ie, they can just hit a link like http://somehost/path/to/report.pdf and they get a pdf report.) Of course the other benefit is that reports only need to be generated once, reducing server load.
    I will definitely try your suggestion and just redirect to the XSQL servlet. I guess I was thinking about it too hard, this is a simple solution which will probably address the problem with a minimum of fuss. ;o) Using XSQLRequest directly works, it's just that I want to be able to reference external images using relative paths... it's funny that relative references to XSL pages works though.
    Thanks again,
    Van
    null

  • Including JSPFs from Java Servlets[Solved]

    EDIT:
    After reading up a bit more on JSP Fragments I realized that they don't work from a Servlet environment. I should have researched a bit more before posting. By switching the files to JSPs, everything works perfectly.
    Original:
    Hopefully I can make this post make sense because there is very little code I can post in a public environment like this. Here goes nothing...
    I have a Servlet, that includes a JSP file using RequestDispatcher.include(). This JSP works fine, and it gets compiled and shown properly. In this "wrapper" jsp, there are multiple calls to various methods in a class which do things such as printing, and including more jspfs, based on the data stored in an XML file.
    For some reason, when including JSPFs from the java methods, the raw JSPF's content is being displayed, rather than a compiled version of the content.
    Here is an example JSPF:
    <%= "Content Coming from a JSPF" %>Here is the code that includes the JSPF:
    this.request.getRequestDispatcher(path).include(this.request, this.response);The JSPF shows up in the right spot and everything, but it's the raw JSPF content, not what it should be showing.
    Am I doing something wrong?
    Thanks,
    -Nivek98
    Message was edited by:
    nivek98

    Hi,
    I dont think you can directly do this
    tagLT %@ include file="/irj/go/km/docs/etc/public/mimes/PMIS/Static%20Contents/sample.html"% tagGT
    check what happens if you directly paste this URL in browser.
    Instead, you can create a KM Document iView from the HTML and paste the URL of the iView in the JSP. Or the best way is to create a page, assign the iViwe to the page and generate a short URL for the page and have this short URL in your include.
    You can check this for short URLs
    http://help.sap.com/saphelp_nw70/helpdata/EN/b3/7b8163404448e7aad7899c0b30313e/content.htm
    Srini
    Edited by: Sinivasan Rajamani on Feb 18, 2010 5:38 AM
    Edited by: Sinivasan Rajamani on Feb 18, 2010 5:36 PM

  • Calling a COBOL stored proc from Java Servlet

    I am trying to call a COBOL stored proc from a Java Servlet. The stored proc is stored on a DB2 database. I need to send 6 inputs to the COBOL stored proc and the output will be the return code of the stored proc. I'm not sure if I'm going about this the right way. This is how my code looks...
    public int callStoredProc(CallableStatement cstmt,
    Connection con,
    String sYear,
    String sReportNbr,
    String sSystemCode,
    String sUserId,
    String sModuleNbr,
    String sFormId){
    int iParm1 = 0;
    try{
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException ex){
    System.out.println("Failed to locate database driver: "
    + ex.toString());
    return iParm1;
    try{
    cstmt = con.prepareCall("{? = CALL MKTPZ90C
    cstmt.registerOutParameter(1, Types.INTEGER);
    cstmt.setString(2, sYear);
    cstmt.setString(3, sReportNbr);
    cstmt.setString(4, sSystemCode);
    cstmt.setString(5, sUserId);
    cstmt.setString(6, sModuleNbr);
    cstmt.setString(7, sFormId);
    cstmt.execute();
    iParm1 = cstmt.getInt(1);
    CloseSQLStatement(cstmt);
    catch(SQLException ex) {
    CloseSQLStatement(cstmt);
    System.out.println("SQL exception occurred:" +
    ex.toString());
    return iParm1;
    return iParm1;
    Could someone tell me if this is the right way to go about doing this?
    Thanks!!!!!!

    I didn't see the code where you create the database connection (variable "con"). However, the answer to your question "Is this the right way...", for me, is "Anything that works is the right way." So try it. That's a first approximation, but once you have something that works you can start on improving it, if that becomes necessary.

  • Execute html file from java code - urgent!!!

    Hi,
    I need help!!
    My application should open html file that located in my computer
    it should be open when some line in JList was choosen
    my question is: How can I open html file from my application
    I work with window XP
    I tried this one :
    Runtime.getRuntime().exec(cmdLine);
    but it doesn't work
    the exeption was: CreateProccess
    Please help! it's urgent!!!!

    http://forum.java.sun.com/thread.jsp?forum=31&thread=497600

  • Capture generated html output from jsf page in bean

    Hi Member,
    I have need to capture the html output coming form jsf page. means aftr rendering what html is displayed before user, we have need to get it in programm.
    like if we use:
    <h:dataTable......>
    <h:colum>heloo</h:column>
    </h:dataTable>
    then their ouput will be:
    <table>
    <tr><td>heloo</td></tr>
    </table>
    and i have need of these complete line with <table> ......</table>
    Please help me...
    Thanks
    Shailendra Kumar

    Thnx for quick reply.
    But i want to capture it in render response phase. May it will be possible??? Is render response phase is responsible for generation of HTML format?? If yes then how can we capture output coming from this phase.
    URLConnection if fine but it still hit server once. I don't want that. I want to store page html format during its view preparation for html.
    Thanks
    Shailendra Kumar

  • Output from java class and display

    I have a big output from a java class after executing a java class... where can store that huge output before I <cflocation to the same page? I need to display the output to the user on the relocated page...Any help appreciated...

    cfsavecontent to a session variable.

  • Write HTML Files from java application

    Hello,
    i have to write HTML files from a java application.
    I am asking if anybody can give me a hint about a good simple solution (library) which can do some of the job for me.
    i know FOP for example is good to create pdf or html from xml, but i dont want to go via xml.
    the sites i need are really very simple presents emails.
    body and maybe a link for next and pervious.
    however, thank you in advance.
    a little hint will also help :)
    Sako.

    That, too, is my question.
    Be the "server" local or remote, wouldn't JSPs still
    be the easier solution? No. it will not. because you need a server. Server for a stand alone application is not esier. according to who said JSPs are easy?
    Its very very difficult.
    >
    When answering, please clarify. I'm a bit of a newbie
    here. :)To get sence about how hard is JSP, check Struts. this is very good open source Framework to simplify the JSPs. but it still complecated enough.
    or Tapestry my lovely open srouce Framework.
    its easier than Struts. but sill complecated because of the documentation.
    All in all, using JSP is the purpose of Java in the internet. but not for me. My application will not be available in the internet, i.e. no server, i.e. no need for JSP.
    i hope that helps a little.

  • How to format html output of a servlet

    Hello.
    My servlet/JSP is processed by custom tags and XSL Translation.
    After all its HTML output looks not formatted.
    How to format it?
    It is possible in a standard way (using a web.xml'd directive)?
    What roughly I want:
    <html>
      <body>
      <body>
    <html>

    I'd try
    indent="yes" in your XSLT's<xsl:output .../>element.
    Hope this helps,
    -Scott

Maybe you are looking for