I would like to have a single JSP page that will do the following:
- If the method is GET and the querystring is NULL, draw a HTML form with a TEXTAREA and SUBMIT button
- If the method is GET and the querystring is not NULL or the method is POST, genete an XML document using GET/POST variables
My first approach draft (test POST or GET) fails syntactically:
query.jsp
<%@ page import="..." %>
<%!
  private void to_xml() {
  ...                
  }
%>
<% if (request.getMethod()="POST") { %>
<?xml version="1.0" encoding="UTF-8"?>
<%
  //generate XML 
  to_xml();
} 
else { 
  //draw HTML form
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>XML Query</title>
    </head>
    <body>
        <form action="query.jsp" method="post">
            <table cellpadding="2">
                <tr><td>Query:</td></tr>
                <tr><td><textarea name="query" cols="60" rows="10" ></textarea>
                <tr><td><input type="submit" value="Go"></td></tr>
            </table>
        </form>
    </body>
</html>
<% } %>
I'm sure that there is a better way to do this, but my experience w/ JSP is limited.
 
    