Web Hosting Talk







View Full Version : Servlets?


Kit
04-26-2006, 09:08 PM
I'm so confused. So I have this project where I need to take form files, parse them, and then generate servlets for them. How do I do that, more specifically, how do I generate the servlets? I just know that for each form there will be 3 methods associated it, one that will display the web-page for the form, the other to process whatever information is submitted (and then puts it into a database) and the other that aggregates the information.

I just don't know how exactly to generate these servlets files, and even after generating them, how are they called?

I'm not sure if this makes any sense, but any help or if anyone can point me in the right direction I'd really appreciate it.

uncleThirteen
04-27-2006, 11:36 AM
Sounds like you need a java guru - servlets are mini java programs.

Sorry if this is too obvious a post...

stdunbar
04-27-2006, 12:48 PM
I'll admit that I've never heard of the design that you're talking about but you're going to want to start with some basic J2EE programming. A HttpServlet is a Java class that can handle things like a HTTP post or get. It can read the information from an HTML form and act on that data.

I'd encourage you to do some reading on what a J2EE web application is. You can start with some overviews at the Sun J2EE site (http://java.sun.com/javaee/index.jsp). Most likely if you only need servlets you'll want to look at Tomcat (http://tomcat.apache.org/). Servlets require a server to run in (the application server) and Tomcat is considered a decent one that is free. It also comes with a bunch of examples to help get you started.

And without pushing you in any particular direction there are many good Java specific forums that can help you out also.

:peace:

Kit
04-27-2006, 05:27 PM
Well, I've worked with TomCat before and I've made servlets and all that by hand. I guess I'm so frustrated because I can understand the project as pieces but I can't seem to understand how to put the pieces together so all I have are tons of files and I'm not sure how they're suppose to interact with each other. :(

stdunbar
04-27-2006, 06:10 PM
Ok, well then what do you need from us? It sounds like you'll either want some sort of templating system or a code generation system. For a template maybe you generate an intermediate file - XML? - that describes what each form does. Then have a single servlet that reads the file to know what to do with the form.

Otherwise, you'll want to generate the Java code for the servlet, maybe modifying the web.xml for the web app and then deploy it.

Just some thoughts.

Kit
04-27-2006, 08:28 PM
Yeah, I need a code generating system I suppose. I guess I'm not quite sure how to generate the servlets via java code. We're not working with XML at all. Blah, thanks for responding though. I guess I'll go bug my professor some more but all his answers just seem so vague because he assumes we knows things that we don't. (e.g. know how to write/work with compilers or whatever)

dollar
04-27-2006, 08:45 PM
What you're trying to do is a bit vague to understand. Are you actually trying to generate servlets on the fly, or are you just trying to output something to the screen based on form variables?

If you are trying to generate true servlets on the fly you most likely need to hand code a servlet that takes the form parameters. It will then generate the servlet.java file and execute a command on the operating system along the lines of: javac servlet.java (where serverlet.java is the name of the created servlet). You may need a few different compiler options depending on your servlet, and might need to move it to the proper directory.

pnorilsk
04-28-2006, 06:01 PM
Apparently the guy is well over his head. It's possible to generate fairly sustainable application code from the business model. But, the information he/she put is so minimal - it's impossible to give any good advice.

Kit, hello - don't be afraid, give us something more.

Peter.