Re: problem with MVC pattern
K Gaur wrote:
public void doGet(HttpServletRequest request,HttpServletResponse
response)
throws ServletException, IOException{
String firstName=request.getParameter("firstName");
String lastName=request.getParameter("lastName");
Please, please, please, please, please do not use TAB characters as the
indent-maker for Usenet listings. Use a low number (up to four) of *spaces*
for each indent level.
the 'music' element is a list box.
Thus when not filled out, sends an empty array or null array to the server.
but when i [sic] leave any of the 3 fields (firstName, lastName and eID)
empty,
rather than showing 'get_missing_fields.jsp' this shows up in browser:
---
java.lang.IllegalStateException: Cannot forward after response has
been committed
servpack.EmailServlet_2_ex6.doGet(EmailServlet_2_ex6.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache
Tomcat/6.0.13 logs.
And the root cause from those logs is what, exactly?
_________________________________________________________________________________
also when all three fields (firstName, lastName and eID) are filled
but
no option in 'music' list box is selected then server returns this:
_________________________________________________________________________
java.lang.NullPointerException
servpack.EmailServlet_2_ex6.doGet(EmailServlet_2_ex6.java:24)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache
Tomcat/6.0.13 logs.
Apache Tomcat/6.0.1
________________________________________________________________________
please tell me where i [sic] m [sic] wrong
You dereference music[0] without ever making sure that music != null and
music.length > 0.
Without the log message from the IllegalStateException I don't see why the
system thinks that you've already committed a response before the dispatch.
You should refactor your code so that the next view is calculated but the
dispatch doesn't happen until the end of the method. Use if-then-else
patterns to reach a single point of dispatch, not multiple points, with the
view correctly selected into a String variable, then dispatch to that variable.
This was not an example of MVC. You separated the view, but the model and
controller are still mixed. Move model logic out into separate classes from
the controller.
--
Lew