Sending data from JSP to Servlet
I'm new to JSP and Servlet programming and I'm sure that'll show through from my questions...
I'm developing a website and have run into a little problem sending multiple items of data from a specific JSP page to the Servlet and would just like to get an idea of how to do it.
The JSP page receives a Vector of objects read from the database and then displays the object data. I am trying to offer the user the ability to edit the data then have this sent back to the controlling Servlet to update the database. My question is, if the user updates several items how do I go about getting this data back to the Servlet?
So far I've just been using blah?action="blah" then checking what action is in the Servlet. I'm assuming there is some other way as, as far as I'm aware, this doesn't allow me to send multiple forms of data?
Really I'm just looking for the best way to retrieve an unknown number of data items from the JSP and for the Servlet to be able to receive them and act appropriately.
[1035 byte] By [
thoseiona] at [2007-11-27 2:40:42]

# 1
Hello,
if you are new to JSP and Servlets, I'll give you a summary of what I know. It may also be useful to browser the API documentation in the javax.servlet.* packages at http://java.sun.com/javaee/5/docs/api/
The base class is javax.servlet.http.HttpServlet. You extend servlets from this class. This class has the methods doGet and doPost that take the arguments HttpServletRequest request and HttpServletResponse response
request is basically the input, while response is the output.
For servlets there are 3 scopes to store and retrieve data: request scope, session scope and application scope. You set and retrieve data in these scopes with the methods setAttribute and getAttribute. The request scope is represented by the request object. You retrieve the session scope by calling the method request.getSession(). From a session, you retrieve the application scope (common scope for all servlets) by calling the method getServletContext() on it. From the request object you can also retrieve the parameters that are passed with the request with the GET or POST method. You have to call the method request.getParameter(...) for this.
The response.getWriter() method returns a writer. What you write to this writer appears in the output.
A JSP page is basically another way for writing a servlet. A JSP is actually converted to a servlet before compilation. The idea is that you use servlets for code and JSPs for output.
JSPs have a 4th scope: the page scope for attributes only visible on the page. This is a subscope of the request scope. A request can include multiple pages. JSPs have some predefined objects, namely
application: the application context of class javax.servlet.ServletContext
session: the session context of class javax.servlet.http.HttpSession
request: the request context of class javax.servlet.http.HttpServletRequest
pageContext: the page context of class javax.servlet.jsp.PageContext
response: the response object of class javax.servlet.http.HttpServletResponse
out: the writer of the response object (of class javax.servlet.jsp.JspWriter)
config: the config of the servlet (of class javax.servlet.ServletConfig)
page: a reference to this JSP page object
You also have custom tags. What they do is that you can define your own tags and when a start tag or an end tag of your own defined tag is encountered in the output, they execute some code. I am not going to explain how custom tags work, but I will tell you the 4 core classes, so you can look for more information in the API documentation: javax.servlet.jsp.tagext.Tag and javax.servlet.jsp.tagext.TagSupport for non iterating custom tags
javax.servlet.jsp.tagext.BodyTag and javax.servlet.jsp.tagext.BodyTagSupport for iterating custom tags.
I hope this helps