Prev: Programming Java 3D API Book Recommendation
Next: Apache Tomcat https link goes down but http works
From: Chris Riesbeck on 28 Jul 2010 18:24 On 7/28/2010 2:02 PM, pmz wrote: > Few more knowledge leaks: > > 1. Let's say I have a sample jsp file, ie: > > <anyJspTag> > <set parameter a="type1" /> > <jsp:include page="mypage.jsp" /> > </anyJspTag> > > Question: Is it possible to access the "a" parameter (with defined or > dynamic) value in the mypage.jsp (which for example contains the > <c:choose /> related to "a" parameter ?) If yes, then I'd be able to > choose some sectors of mypage.jsp which should be visible regarding to > request parameters - true? Either of the following works to pass info to an included page: <c:set var="someVar" value="..." scope="request" /> <jsp:include page=... /> - inside the included page, use ${someVar} to access the value - the scope is needed; by default, variables are page scope, i.e., not shared across pages or <jsp:include page=...> <jsp:param name="someVar" value="..." /> </jsp:include> - inside the included page, use ${param.someVar} to access the value > > 2. I'd like to build a menu with submenus from standalone XML file - > how shall I start? How ppl do it? JSTL has XML processing forms but I've not used them. A JSTL quick reference I quite like (http://www.cs.uiowa.edu/~slonnegr/wpj/jqr.pdf) gives this example: <c:import var="rss" url="http://servlet.java.sun.com/syndication/rss_java_highlights-PARTNER-20.xml"/> <x:parse var="news" xml="${rss}"/> which puts parsed XML data into "news". > > I need to change my php-thinking into jsp-thinking - that's quite > difficult, but I'm trying. Some of it is going to model-view-controller which is a more general concept than Java. Even though JSTL has some nice SQL tags, I don't use them because it puts too much business logic in the presentation layer.
From: Arne Vajhøj on 28 Jul 2010 20:12 On 28-07-2010 13:31, pmz wrote: > 2. I'm trying to build bit complex website based on JSP (which I've > done a lot in PHP, so the main idea of website engineering is quite > common for me), but I a bit confused about the architecture/structure > of a JSP webpage building. The problem is, I'm not able to imagine in > my mind, how the architecture (directory structure) should be found, > how do I divide the template files, the engine core, etc. > > 3. What I've done in PHP, is quite simple structural solution, which > looked like following: > > mainFile { > switch( __mainArgument from _GET ) { > case "myPlugin": > include "myPlugin.inc.php"; > break; > /// And so on, and so on > } > } > > The problem is, that the switch() java statement is not supporting > Strings - okay - so I'm not able to such as above. You could use if statements. But you really should use a servlet instead of a JSP page to do that. Which could either be your own servlet or one of the many MVC web frameworks. > That does not > matter at all, because I thought that I'll just divide my website into > subfolders, such as: > > Web Pages \ > \index.jsp > \news\index.jsp > \users\index.jsp > \requests\index.jsp > > That sollution is quite okay for me - any other suggestions? I do not see the correlation with the previous section, but it seems OK. > - but I > was wondering what about dynamic elements, which are visible in any > index.jsp (and \*\index.jsp) file? Let me show it on an example: > > /// index.jsp > <html> > <body> > <div> > [DEPEND ON \%s\index.jsp CONTENT HERE] [1] > </div> > <div> > [DEFAULT CONTENT of \%s\index.jsp] [2] > </div> > </body> > </html> > > The [2] position is quite simple, because it might be defined directly > in my file, but what if I include in [1] position a file, which is > also included in base index.jsp (ROOT)? There should be a submenu > display, which should display menu items regarding to the module > selected. If you want to do that then I think you should look at something like Tiles. > Shall I use the mod_rewrite (ie. /any_here/index.jsp> /index.jsp? > module=any_here - then the request parameter fetching is much easier. I do not see any need for mod_rewrite. Arne
From: Wojtek on 28 Jul 2010 20:11 pmz wrote : > Dear Group, > > 1. At the beginning I'd like to apologize you for any mistakes or > misunderstood's, which might occur in message below, but I'm a quite > beginner in JSP so maybe some of my problems aren't really problems ;) > My Java knowledge is intermediate, but the structures of JSP or JSF or > any other frameworks is pretty bad, but I do not have any idea how to > start. > > 2. I'm trying to build bit complex website based on JSP (which I've > done a lot in PHP, so the main idea of website engineering is quite > common for me), but I a bit confused about the architecture/structure > of a JSP webpage building. The problem is, I'm not able to imagine in > my mind, how the architecture (directory structure) should be found, > how do I divide the template files, the engine core, etc. > > 3. What I've done in PHP, is quite simple structural solution, which > looked like following: > > mainFile { > switch( __mainArgument from _GET ) { > case "myPlugin": > include "myPlugin.inc.php"; > break; > /// And so on, and so on > } > } > > The problem is, that the switch() java statement is not supporting > Strings - okay - so I'm not able to such as above. That does not > matter at all, because I thought that I'll just divide my website into > subfolders, such as: > > Web Pages \ > \index.jsp > \news\index.jsp > \users\index.jsp > \requests\index.jsp > > That sollution is quite okay for me - any other suggestions? - but I > was wondering what about dynamic elements, which are visible in any > index.jsp (and \*\index.jsp) file? Let me show it on an example: > > /// index.jsp > <html> > <body> > <div> > [DEPEND ON \%s\index.jsp CONTENT HERE] [1] > </div> > <div> > [DEFAULT CONTENT of \%s\index.jsp] [2] > </div> > </body> > </html> > > The [2] position is quite simple, because it might be defined directly > in my file, but what if I include in [1] position a file, which is > also included in base index.jsp (ROOT)? There should be a submenu > display, which should display menu items regarding to the module > selected. > You need to do a paradigm shift. In PHP you include files selectively mostly for performance reasons, as you do not want the interpreter parsing logic which will not be used during that page hit. Using Java, the JSP is a servlet which is compiled once into a class, then used after that. In most cases the JSP servlet class remains in server memory so load times are very fast. Because the JSP is compiled once as a whole, it is impossible to selectively include files for each page hit. If the included files have differing processing logic, then you really should move that logic into the application as classes and servlets. A JSP should only contain enough logic to support display requirements not processing requirements. -- Wojtek :-)
From: Arne Vajhøj on 28 Jul 2010 20:16 On 28-07-2010 14:54, pmz wrote: > On 28 Lip, 20:37, Chris Riesbeck<Chris.Riesb...(a)gmail.com> wrote: >> On 7/28/2010 12:31 PM, pmz wrote: >>> 1. At the beginning I'd like to apologize you for any mistakes or >>> misunderstood's, which might occur in message below, but I'm a quite >>> beginner in JSP so maybe some of my problems aren't really problems ;) >>> My Java knowledge is intermediate, but the structures of JSP or JSF or >>> any other frameworks is pretty bad, but I do not have any idea how to >>> start. >> >> Personally, I prefer JSTL over straight JSP, to reduce jumping back and >> forth between HTML and Java syntax. So iteration over a collection is >> >> <ul> >> <c:forEach var="item" items="${myObj.thingies}"> >> <li><c:out value="${item}" /></li> >> </c:forEach> >> </ul> >> >> instead of >> >> <ul> >> <% for (Object item : myObj.getThingies()) { %> >> <li><%= item %></li> >> <% }<%> >> </ul> >> >> With more nesting, those separated braces get annoying fast. > > That's true and I think I'll try using those, too. My question is, > shall I make any changes in environment of NetBeans to use JSTL? File > extensions? Additional libraries? But okay, if it's obvious and I'll > find it by googling for it, ignore my questions. Maybe your servlet container comes with JSTL support. Otherwise you can download an implementation like: http://tomcat.apache.org/taglibs/standard/ and put the two jar files in WEB-INF/lib. Then you need to put taglib definitions in top of your JSP pages. Like: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> > The base idea is: Let's say I have few packages which contain database > access, data management and some others, which are pure Java objects, > without any HTML stuff. What I want to achieve, is to work over the > data I fetch or I submit in JSP pages. > > I'd like to have ONE default JSP page (which obviously contains a > webpage main layout - styles, scripts, tables, images, etc.). In few > places I have some dynamical stuff (such as parameter-regarded menu > display or also parameter-regarded body display). > > Shall I use you<c:choose/> method for further inclusion of required > jsp-sub-pages? You should use a servlet for that. JSP page = View Servlet = Control Arne
From: Arne Vajhøj on 28 Jul 2010 20:18
On 28-07-2010 15:02, pmz wrote: > Few more knowledge leaks: > > 1. Let's say I have a sample jsp file, ie: > > <anyJspTag> > <set parameter a="type1" /> > <jsp:include page="mypage.jsp" /> > </anyJspTag> > > Question: Is it possible to access the "a" parameter (with defined or > dynamic) value in the mypage.jsp (which for example contains the > <c:choose /> related to "a" parameter ?) If yes, then I'd be able to > choose some sectors of mypage.jsp which should be visible regarding to > request parameters - true? The syntax is a bit different. http://java.sun.com/products/jsp/tags/11/syntaxref1112.html Arne |