JSP Web-Development [newbie]

C

Chris Riesbeck

With newer versions:

<li><c:eek:ut value="${item}" /></li>

can even be written as:

<li>${item}</li>

c:eek:ut will convert HTML special characters to entity code. ${item} by
itself does not. I've been bit by that several times when ${item} was a
string with < in it.
 
C

Chris Riesbeck

JSP isn't exactly a "template" framework as you might think of it, but
close enough for now.

And once you understand JSP, it's not hard to move on to the zillion
template frameworks built on top of it.

IBM Developerworks is very worthy, too.

Yes, that's the part of IBM I meant. A lot of neat technology and some
very well-written articles have come out of there.
 
P

pmz

Dear Friends (ain't Group ;),

I'm really surprised about your huge response for my problems. That's
really kind. I'll analyze suggestions you've mentioned above and I'll
try to fetch the best solution for my application.

I've discovered that such enthusiasm was not found by me in the C/C++
(or plenty more devlangs) sections of google groups, that's weird,
isn't it?
Now I'm pretty sure that I may share any of my problems here and they
won't stay without an answer. While I'm exploring the Java world,
which in fact gives me a lot of fun, that's a big bonus. There is no
hurry in my project, so I'll try to do my best and use your advices to
build the perfect (mostly) one.

Once again, I'd like to thank all of you for help - if any problems
occur, I won't hesitate writing'em here.

All the best,
Przemek M. Zawada
 
P

pmz

Dear Friends,

As I mentioned before, I have a simple modular structure of my
website. Let me describe it as:

- Main page, which contains a menu bar with few page-links, ie.
- News
- Users
- Requests
- Options
- Anything more

Each page-link has sub-links, as following: “New”, “Edit”,
“Browse” (typical).
(In PHP, I’d href them like: “/news/add” or “/users/browse”)

What I’ve been doing lately in PHP, I’ve used a mod_rewrite powerful
tool, which rewrites me request string like so:

if(!index.php)
rewrite /any/friendly/url to /index.php?p=any/friendly/url

Inside the index.php I’ve parsed the “p” argument into ARGV/ARGC-style
based Array – ARGV[0] -> any, ARGV[1] -> friendly, ARGV[2] -> url,
etc. Cool.

When it was done, I’ve build big switch statement, which direct the
HTML-output regarding to ARGV[0-n] parameters, as following:

$PageObject = HTML_TEMPLATE(“index.tmpl”);

switch(ARGV[0]) {
case “news”:
switch(ARGV[1]) {
case “add”:
// Do something
$PageContentElement = HTML_TEMPLATE(“subpage.tmpl);
$PageContentElement->Add(“add some data here”);
$PageObject->Add(“PageSection_Menu”,
$PageContentElement->GetObjectHTML());
break;
case “edit”:
// Do something else
break;
}
break;
case “users”:
// analogical as in “news” case
break;
// other cases
}

$PageObject->DisplayHtml();
/*
print out <html>*</html> main template including the replaced
variable elements
*/

The PageObject is a simple template engine, which I’ve wrote to parse
pure-HTML files, which contain {Variable} elements, which might be
changed by RegExp with defined value (depending on switch statement
and ARGV variables).

At the end, I just printout the PageObject data, with changed content
– done.
That was my idea of PHP webpage engine and as I see that logic is
quite impossible in JSP. Here the problems occur.

I wish you understand how my php-logic seems to work, now tell me
please, how do I rewrite it into JSP style?

As I understood, I may create a index.jsp file, which contains the
default page template (including menus, footers, all that crap), with
links to my modules – ie. /news or /users.
I’ve been told, that I may connect the /news url with some java
servlets (via web.xml). Sounds cool, but is it possible to connect the
main index.jsp file with servlet output? On the other hand, is it
possible to get from index.jsp a page template layout and copy/move it
to my servlet element?

I don’t have any problems with dividing my pages into plenty jsp
pages, but what I want to achieve is NOT make changes in each jsp page
in the static sectors (like menubars, styles, etc.) When there are few
files, n/p, but when I build like 20 sections, that would be annoying.

Oghr, don’t be mad on me, I’m trying to understand everything. Now
when I’ve clarify my application structure, I presume it might be
easier for you to understand what I really want :)

Thank you,
Przemek M. Zawada
 
L

Lew

pmz said:
I've discovered that such enthusiasm was not found by me in the C/C++
(or plenty more devlangs) sections of google groups, that's weird,
isn't it?

This isn't a "section of Google Groups" (despite that I'm using GG to
post this response right now). Google Groups merely echoes the Usenet
forum, and really isn't even the best way to access the forum. GG
echoes tons of spam and other garbage that other newsgroup servers
filter, and the browser has no capability to filter the spam that does
get through. Google for "newsgroup reader", or use Mozilla
Thunderbird as a minimally acceptable client. You will need to
connect to a newsgroup server - like a mail server but specifically
for news feeds - to get the good experience.
Now I'm pretty sure that I may share any of my problems here and they
won't stay without an answer.

Of course you will have to deal with posters like me who reply
enthusiastically but not always kindly, humbly or diplomatically.
Bear in mind that sarcasm or rhetorical tricks don't necessarily
indicate unhelpful responses; sometimes one is cruel to be kind. To
pick one of the most popular examples, the initialism "GIYF", or
"Google Is Your Friend", is dismissive in tone but embodies the
extremely empowering advice to use the search tools available to find
answers rather than ask stupid questions. Build a man a fire and you
warm him for an hour. Set a man on fire and you warm him for the rest
of his life.

Kidding aside, most of us most of the time mean to help whether or not
we add attitude as a bonus feature. Also, Usenet is a discussion
medium, not a help desk. You usually can get good advice, but much of
the joy comes from the spirited discussion and diversity of opinions
people express.
 
P

pmz

This isn't a "section of Google Groups" (despite that I'm using GG to
post this response right now).  Google Groups merely echoes the Usenet
forum, and really isn't even the best way to access the forum.  GG
echoes tons of spam and other garbage that other newsgroup servers
filter, and the browser has no capability to filter the spam that does
get through.  Google for "newsgroup reader", or use Mozilla
Thunderbird as a minimally acceptable client.  You will need to
connect to a newsgroup server - like a mail server but specifically
for news feeds - to get the good experience.

Don't be so precise, but I'll think about it - thank you. Anyway, the
Google gives me ability to "read and share wherever I am" the usenet.
Of course you will have to deal with posters like me who reply
enthusiastically but not always kindly, humbly or diplomatically.
Bear in mind that sarcasm or rhetorical tricks don't necessarily
indicate unhelpful responses; sometimes one is cruel to be kind.  To
pick one of the most popular examples, the initialism "GIYF", or
"Google Is Your Friend", is dismissive in tone but embodies the
extremely empowering advice to use the search tools available to find
answers rather than ask stupid questions.  Build a man a fire and you
warm him for an hour.  Set a man on fire and you warm him for the rest
of his life.

Kidding aside, most of us most of the time mean to help whether or not
we add attitude as a bonus feature.  Also, Usenet is a discussion
medium, not a help desk.  You usually can get good advice, but much of
the joy comes from the spirited discussion and diversity of opinions
people express.

True, true and true. I'm not afraid of Google power so at first I look
for answers there. Unfortunately, some things are not found, because
they are not just syntax or function questions - the ideas and
techniques rarely are posted. Nevertheless, I did find some
interesting topics, Q&A, FAQ or tutorials, which I read carefully and
tried to follow them. As you see, I do not ask for "how do I declare a
Object variable?", because such answers are found in each manual
website.

The sarcasm you've mentioned - believe me, I know what you are talking
about and I'm kind of immune for it.

All the best,
Przemek M. Zawada
 
P

pmz

No. You're doing this all wrong. Or rather, you're doing it all PHP, which
in JSP means wrong.

Use separate pages for the different pages, and a tag file to define the
common structure:

http://www.oracle.com/technology/sample_code/tutorials/jsp20/tagfiles...

A tag file is the analog of a framework method in code; it can write a
load of HTML, but can also invoke fragments passed by the original
invoker.

For example, given a tag file like this (call it main.tag):

<%@ attribute name="content" required="true" fragment="true" %>
<html>
  <body>
   <h1>PMZ's SUPER SITE</h1>
   <jsp:invoke fragment="content"/>
  </body>
</html>

You could write a JSP like this:

<%@ taglib prefix="mytags" tagdir="/WEB-INF/tags" %>
<mytags:main>
  <jsp:attribute name="content">
   <p>Some content.</p>
  </jsp:attribute>
</mytags:main>

This would invoke the main.tag to build the page structure, which would
then call down to the fragment defined in the JSP. You can have multiple
fragments, and also use normal content of the tag via <jsp:doBody/>.

tom

I think I'm getting it now.

P.
 
P

Przemek M. Zawada

W dniu 2010-07-28 22:00, markspace pisze:
In the WEB-INF/web.xml file, you'd bind a pattern to a name, like this:

<servlet-mapping>
<servlet-name>MainPlugIn</servlet-name>
<url-pattern>/myPlugin</url-pattern>
</servlet-mapping>

That replaces mod_rewrite, and maps the url pattern after your hostname
to the name MainPlugIn. Now you have to do one more thing to map the
name MainPlugIn to some code.

<servlet>
<servlet-name>MainPlugIn</servlet-name>
<servlet-class>myplugin/plugin.jsp</servlet-class>
</servlet>
....

Also, try reading the servlet specifications, it's are surprisingly
readable.

<http://jcp.org/aboutJava/communityprocess/final/jsr154/index.html>

Java EE 6 Tutorial.

<http://download-llnw.oracle.com/javaee/6/tutorial/doc/>

Well, I've tried your method above (this mapping) - seems to work, but I
still have some difficulties with web layout. I'm browsing the netbeans
tutorials - interesting.

P.
 
A

Arne Vajhøj

c:eek:ut will convert HTML special characters to entity code. ${item} by
itself does not. I've been bit by that several times when ${item} was a
string with < in it.

True.

But I would expect that to only be needed in relative
few cases due to input validation rejecting input with
<> in.

Arne
 
A

Arne Vajhøj

It is not uncommon to spec requirements for an app to run. And some
kinds of portability are overrated. I'm not necessarily speaking in
favor of mod_rewrite, but I do think httpd is an awesome product and one
should not be ashamed or fearful of basing an application on it.

And there are hundreds of products on the market that already spec it as
part of their product. Ever hear of LAMP?

But Java web apps are not supposed to be tied to a specific
web server.

But I don't think that is the case here.

Certainly mod_rewrite is Apache specific, but the functionality
can be implemented with other software.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top