Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: doGet and doPost not supported in URL

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default doGet and doPost not supported in URL

    For a code I am working on I'm using servlets with jsp. In the servlets I have doPost and doGet with certain servlets that I want to get something on the server or to add it. In the jsp I have the method of post and get in the form. Each time I run my code I cannot get anything that is on the server, i get an error saying http get method not supported on the server same with post. Can someone look at the code and see if there is anything missing. I have been looking at this for many times and I cannot get it to work. Here is some of my servlets and jsps:

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class AddTagServlet extends HttpServlet{
     
    	private static final long serialVersionUID = 1L;
     
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     
    		boolean isSuccess= false;
     
            String isbn13 = request.getParameter("isbn13");
            Tag tag = new Tag();
     
            tag.setIsbn13(isbn13);
            tag.settag(request.getParameter("tag"));
     
            TagDAO tagdao = DAOUtilities.getTagDAO();
            isSuccess = tagdao.addtag(tag);
     
            if(isSuccess){
                request.getSession().setAttribute("message", "Tag successfully added");
                request.getSession().setAttribute("messageClass", "alert-success");
                response.sendRedirect(request.getContextPath() + "/ViewBookDetails?isbn13=" + isbn13);
            } else {
                request.getSession().setAttribute("message", "There was a problem updating this tag");
                request.getSession().setAttribute("messageClass", "alert-danger");
                request.getRequestDispatcher("bookDetails.jsp").forward(request, response);
            }
        }
     
    }
     
     
    public class BookPublishingServlet extends HttpServlet {
     
    	private static final long serialVersionUID = 1L;
     
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     
    		// Grab the list of Books from the Database
    		BookDAO dao = DAOUtilities.getBookDAO();
    		List<Book> bookList = dao.getAllBooks();
     
    		// Grab the list of Book tags from the Database
    		TagDAO tagdao = DAOUtilities.getTagDAO();
    		List<Tag> tagList = tagdao.getAllTags();
     
     
    		// Populate the list into a variable that will be stored in the session
    		request.getSession().setAttribute("books", bookList);
    		request.getSession().setAttribute("tags", tagList);
     
    		request.getRequestDispatcher("bookPublishingHome.jsp").forward(request, response);
    	}
    }
     
     
     
    <section class="success">
    	  <div class="container">
     
    		<h1><small>Add Tag</small></h1>
     
    		<form action="AddTag" method="post" class="form-horizontal">
     
    		  <input type="hidden" class="form-control" id="isbn13" name="isbn13" placeholder="ISBN 13" required="required" value="${book.isbn13}" />
     
    		  <div class="form-group">
    		    <label for="tag" class="col-sm-4 control-label">Tag</label>
    		    <div class="col-sm-5">
    		      <input type="text" class="form-control" id="tag" name="tag" placeholder="Tag" required="required" />
    		    </div>
    		  </div>
    		  <div class="form-group">
    		    <div id="popover-bookpub-addtag" class="col-sm-offset-4 col-sm-1">
    		      <button type="submit" class="btn btn-info">Add Tag</button>
    		    </div>
    		  </div>
    		</form>  </div>
     
     
    <td><c:out value="${book.isbn13}" /></td>
    						<td><c:out value="${book.title}" /></td>
    						<td><c:out value="${book.author}" /></td>
    						<td><c:out value="${book.publishDate}" /></td>
    						<td><fmt:formatNumber value="${book.price }" type="CURRENCY"/></td>
    						<td><form action="DownloadBook" method="get">
    								<input type="hidden" name="isbn13" value="${book.isbn13}">
    								<button class="btn btn-success">Download</button>
    							</form></td>

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: doGet and doPost not supported in URL

    What software runs on the server?
    Are there any configuration steps that need to be taken? For example on Tomcat there needs to be entries in the web.xml file.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: doGet and doPost not supported in URL

    I am using wildfly 19. I tried to add the servlet mapping and servlet classes on the web.xml but that didn't do anything different. But other than that I haven't tried anything else on the web.xml

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: doGet and doPost not supported in URL

    Look at some working samples and copy the placement and logic they use.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jul 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: doGet and doPost not supported in URL

    I was able to get the doGet to work, I'm still having trouble with the doPost. I will look at examples and see if they can help. Thank you! 😊

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: doGet and doPost not supported in URL

    What did you do to get the GET to work? Can you post the details so others can benefit?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jul 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: doGet and doPost not supported in URL

    All I did was run my DAOs after connecting them to my sql. I didn't do anything different to the code, so the method for get was correct for my code.

Similar Threads

  1. SourceDataLine not supported pan
    By leviorr in forum The Cafe
    Replies: 0
    Last Post: December 30th, 2013, 03:43 AM
  2. Why my POJO is not working in my doPost servlet?
    By tangara in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2013, 08:37 AM
  3. How can I call doGet method?
    By Nuha_IT in forum Java Servlet
    Replies: 4
    Last Post: November 27th, 2012, 07:27 AM
  4. [SOLVED] Why can't I write to file inside a doGet() method?
    By FailMouse in forum Java Servlet
    Replies: 1
    Last Post: July 7th, 2010, 01:15 AM
  5. IllegalArgumentException: Pan not supported
    By rtumatt in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 13th, 2010, 01:00 PM

Tags for this Thread