Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6019101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:22:19+00:00 2026-05-23T03:22:19+00:00

I would like to have a single JSP page that will do the following:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:22:20+00:00Added an answer on May 23, 2026 at 3:22 am

    As to your concrete problem: in Java, strings are objects, not primitives. You need to compare objects by the Object#equals() method, not by equality operator == (or even more incorrectly, the assignment operator =). This is not different when writing raw Java code straight in a JSP file instead of a Java class.

    <% if (request.getMethod().equals("POST")) { %>
    

    As to the better way, just use a servlet.

    Put JSP in /WEB-INF/query.jsp to prevent direct access and remove all old fashioned scriptlets so that it becomes a fullworthy view.

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>XML Query</title>
        </head>
        <body>
            <form action="query" 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>
    

    Create a servlet which does the controlling job:

    @WebServlet(urlPatterns={"/query"})
    public class QueryServlet extends HttpServlet {
    
        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            if (request.getParameterMap().isEmpty()) {
                showJsp(request, response);
            } else {
                showXml(request, response);
            }
        }
    
        private void showJsp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.getRequestDispatcher("/WEB-INF/query.jsp").forward(request, response);
        }
    
        private void showXml(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // ...
        }
    
    }
    

    Open the page by http://localhost:8080/contextname/query.

    I however wonder how it’s useful to mix POST/GET here since you want to intercept on the query string as well. Just remove method="post" from the <form> and replace service() method name in above example by doGet(). This way the form submit URL becomes bookmarkable as well (which is what among others Google also does).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single user java program that I would like to have store
I have several sites (Asp.Net) that I would like to have a single sign
I would like to have a single DatagramSocket to listen for both unicast and
I have a problem that I would like have solved via a SQL query.
I would like to have different URLs pointing into different segments of a single
I would like to have a complex form that uses various VBA script files.
I would like to have a reference for the pros and cons of using
I would like to have an iframe take as much vertical space as it
I would like to have a VM to look at how applications appear and
We would like to have user defined formulas in our c++ program. e.g. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.