tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p niemandt <mau...@acesurfer.co.za>
Subject Re: is there a tag or some kind of mechanism that would do the following ...
Date Tue, 25 Feb 2003 22:45:06 GMT
Nope: More a continuation of this one.

Basic programming principles / for principles, see laziness ;-)

Anyways: What I did was to write a few small static functions, 
some just to write some headers, some more complicated (writing IE, Moz
applet headers type of thing).

my functions usually followed the following syntax

public static void writeHeader(PrintWriter pw, String title) {
	pw.write("<head>");
	pw.write("<title>");
	pw.write(title);
	pw.write("</title>");
	pw.write("<head>");
}

etc, etc, ... ad infinitum.


I also have some overloaded functions, type of 

public static void writeHeader(PrintWriter pw, String title, int
headerLevel) {
	....
}


The basic idea stays the same: write some static functions, do the
processing there. You could, for example, build a hierarchy for a
customized look and feel. { Which, I know, can be done better using
other techniques, but when the only tool you have is a hammer, all
problems resemble a nail ... }

{Of course, the more you use and extend it, the closer you'll get to
basically using something like struts.}

{Of course, a plain simple function like getQuotedString(String sz) {
	return "\"" + sz + "\"" 
}

tends to be used all over the place.

---

At least from a develop perspective, this could make your servlet a lot
easier. You can then do stuff like 


void doPost(HttpServletRequest req, HttpServletResponse resp) {
	PrintWriter pw = req.getWriter();

	MyLook.writeHeader(pw, "Request Header");
	MyLook.writeTableHeader(pw, "Request Table");

	MyLook.writeTableRow(pw, "Request Table", LookFeel.RowOpen);
	for (....) {
		MyLook.writeTableCell(pw, "Request Table");
	}
	MyLook.writeTableRow(pw, "Request Table", LookFeel.RowOpen);
	pw.flush();
}

Anyways: Just an idea: But, it's usually better to separate the two, use
some scripting language to do your presentation layer, using something
like jsp, xslt, javascript, whatever, while your logic is contained in
the servlet. Do a google on Model View Controller.


hth,
Paul


On Tue, 2003-02-25 at 09:18, Mufaddal Khumri wrote:
> I could use a giant String being returned from some static method .. 
> but the problem is that i would have to do the following:
> 
> static String getString()
> {
> 	String str = "<html>"
> 			+"<title>"
> 			+"ding dong bells"
> 			+"</title>"
> 			+"<body></body></html>";
> 	
> 	return str;
> }
> 
> In the above code i will have to type in the quotes and + signs 
> everywhere since if the string gets too long it will all be on one line 
> and the html code from a developer stand point would not be 
> maintainable.
> 
> Are there any other better ideas to do this ?
> 
> Mufaddal.
> On Tuesday, February 25, 2003, at 01:57  PM, Mufaddal Khumri wrote:
> 
> > Hi,
> >
> > Many times we come across a lot of out.println( ... ) statements in 
> > our servlets:
> >
> > public class MyServlet extends ....
> > {
> > 	....
> > 	....
> >
> > 	doPost( ... )
> > 	{
> > 		.....
> > 		.....
> > 		out.println("<html>");
> > 		out.println("<title>");
> > 		out.println("ding dong bells");
> > 		out.println("</title>");
> > 		out.println("<body>");
> > 		out.println("</body>");
> > 		out.println("</html>");
> > 		......
> > 	}
> > }
> >
> > I do know that if your code has more html .. its better to write a 
> > .jsp file instead of a servlet.java file
> > There are some cases where this is unavoidable and I was wondering if 
> > there was a way to do something like below in a .java file:
> >
> > public class MyServlet extends ....
> > {
> > 	....
> > 	....
> >
> > 	doPost( ... )
> > 	{
> > 		.....
> > 		.....
> >
> > 		<Some kind of tag that signals to the compiler that whatever follows 
> > is to be "out.println(... )" >
> > 		
> > 			<html>
> > 			<title>
> > 				ding dong bells
> > 			</title>
> > 			<body>
> > 			</body>
> > 			</html>
> > 	
> > 		</end of the signalling tag>
> > 		......
> > 	}
> > }
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
-- 
p niemandt <maudib@acesurfer.co.za>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message