• Post Reply Bookmark Topic Watch Topic
  • New Topic

best way to organise form & submit processing in pages

 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this is a general question which i thought i knew the answer to but actually don't - i've got a form on one page, with loads of pictures and text and such stuff.
then i've got a results page which processes the submitted form and it also has content and stuff.
designers who don't have much of a clue about jsp and only grasp html may work on the pages to tart them up a bit.
i want the form validation to be able to redisplay the page with all the user's entries in the form fields & an error message if it's wrong.
i want the form field names and other constants to be held in java constants and only defined in one place but used by all pages involved (there might be others).
First Q: assuming i'm going to migrate to servlets v. soon but must write this all now in just JSP (no beans/servlets), where should I put the validation code?
Q2: where should I put the form field name constant declarations?
TIAAdam
 
Po-yu Chien
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, I suggest you to use struts framework available at http://struts.jakarta.org
However, struts framework is servlet-bean-jsp focused.
In your case, I think your form validation can be written in top
of your jsp page containing the form. If everything goes right,
forward to another page, if not, display the error message, and fill textboxes` value with <%=request.getParameter('??')%>.
This should be what you want, however, I still strongly suggest
using struts. JSP is not meant to be used like PHP or ASP...
Regards
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off- JSP's only is not a recommended way of java server programming. Model-View-Controller(MVC) pattern is a baseline that you should start with. Anyway, an easy way of doing validation is via java script. Especially if your not really familiar with jsp and servlets. Remember- JSP is a combination of HTML and javascript, so you can write javascript as you normally would. JSP insider has some good stuff on using java script, and java world has some articles on form validation. You can't do much,(in any effective way)if your only using JSP.
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't i know that jsp only isn't the recommended way of programming!!!
however that is what is imposed on me with the test server i'm working on, because it's actually live and i can't stop the webserver for a recompile or anything. so it's not a development server i'm developing on. ok, so i should set up tomcat on my pc, but i haven't got my own pc, i move from pc to pc depending on which is free. don't worry, i know how cr*p this is and i'm working on changing it.
OK so I can figure out struts when I've got my development environment set up properly. by the way, the link was wrong, it's:
http://jakarta.apache.org/struts
but another question, and i'd be interested to know if struts answers it: with a website application that's got a standard look and feel throughout, the top and sides of the page are always the same from page to page (apart from dynamic menu content etc), so I hold this in include files as bare HTML, right?
so how do the graphic designers get at the pages I develop the most easily? how do they edit the HTML in the JSP I write? since the top and sides of the page aren't there, they complain. What's the best software for them to use? Dreamweaver ultraedit or something like that?
Thanks for the help
Adam
 
Po-yu Chien
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting the wrong url :b
To answer your question regarding struts, no, I don`t see anything that can help you, except struts-template tag library.
However, I haven`t used it. My policy is that programmer do not touch pages before UI designer have finished doing with them.
In larger projects however, all page designer have basic knowledge about jsp and java. So...either have your page designer get used to it, or change page designer?
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Po-yu Chien, you're obviously a tough man to work for ;-)
i thought one of the points of JSP was that the HTML could be seperated from the code so the page designers could work with it more easily.
 
Po-yu Chien
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with your comment, however it is difficult to have less skilled page designer get used to even template thing!
For those who just cannot code html with text editor(Those who do not know html tags), they just mess up your jsp, even if you wrap thing in tag lib. But take into consideration that I`m not a full-time programmer, my work experience is limited in part-time projects mostly lead by professor in my college. And I`m an above average page designer too(Compared to the many I had to work with), so I can even improve page layout once I get rid of their presence. But this works only for smaller projects. However, in larger, more structured projects everyone chosen had enough knowledge to deal with jsp, so there is not such problem.
Well, comments from my limited experience;-)
By using template, jsp can be worked separately. But you get to have page designer good enough...
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello... this URL might help you ... It did for myself. It uses hash tables to store the information, javabeans and the MVC approach:
http://www.javaworld.com/javaworld/jw-03-2000/jw-0331-ssj-forms.html
If you'd like to see it running, check http://www.mycgiserver.com/~aegcp/test/form.jsp
cheers
-andres
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That article makes me realise I don't know enough about servlets to be able to make a valid judgement on it!
As for the page designers, I guess you're right, it's not such a big problem. I'll just try to keep the amount of JSP tags in the HTML as small as possible. What's the most I'm going to need? Loads of little taglets for filling in form values, and the occasional loop & try / catch block for lists.
Right, I'm off to learn how to implement servlets properly.
thanks,
Adam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!