The original servlet would then update, either automatically (preferably) or by hitting the browser's refresh button, and show the new entry
Devin Crane wrote:Those articles helped a lot.
Let me make sure I understand:
Servlet A displays information from a database via jdbc and also has an Add button.
If Servlet A's Add button is clicked, a JSP page is called
which creates a form that allows the user to add a new entry to the database via JDBC when a Submit button is selected. This is sent to the browser.
Once submitted, Servlet B is called, with the information from the form, and Servlet B updates the database.
Servlet B calls Servlet A again, thereby displaying the db information, including what was just added.
But just to be clear, the JSP could do Servlet B's job; it's just bad design to.
Jul 08, 2013 2:51:48 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet hello as unavailable
Jul 08, 2013 2:51:48 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet hello
java.lang.ClassNotFoundException: test.addServlet
at org.apache.catalina.loader.WebappClassLoader.loadClas
Devin Crane wrote:
Does this new servlet, addServlet.java, also go into the hello directory "webapps/hello/WEB-INF/classes/test/*.java" or go into a different directory?
The form simply specifies an action that is a task controller servlet
Devin Crane wrote:Sorry, I meant .class, not .java.
Yeah, it was kinda dumb to use the onclick that way, I took it from the way I invoked the JSP form the servlet, using what you'd mentioned earlier:
though it seems like it would be easier to just bypass the servlet and go straight to a new JSP.
For some reason I'd assumed JSPs were limited to just HTML.
I'm assuming the lack of comment on the web.xml means I did that correctly.
Devin Crane wrote:I'm assuming the lack of comment on the web.xml means I did that correctly.
Devin Crane wrote:display.jsp works, except for the add button so it doesn't currently go anywhere.
It appears a form, rather than a button, would make it easier so I think I will use it, but display.jsp has no info to pass on.
Devin Crane wrote:If I change the 2nd servlet-name to 'add' and the servlet-pattern is '/addServlet', wouldn't I call addServlet from the form's action with "/add/addServlet"?
<form action="/addServlet" method="get">
<servlet-class>test.addServlet</servlet-class>
Devin Crane wrote:I was not making stuff up. I was just trying to follow the same pattern as /add/addServlet, and I couldn't remember what the context path was.
I definitely would never have guessed to use ${pageContext.request.contextPath}.
You're right, class names do, by convention, start with a capital letter, one convention I'm bad at remembering. I make methods more than I make classes so camelcase is on my mind more.
, which url in the browser says:HTTP method POST is not supported by this URL
http://localhost:8080/hello/submitForm
Devin Crane wrote:
This is my code to redirect to my original servlet to display the db info:
I'd have thought a servlet that can receive POST calls can invoke another servlet that doesn't
Any ideas?
Consider Paul's rocket mass heater. |