tags:

views:

49

answers:

2

Hi All! I new in JSP, i have a problem with JSP

in php i use

$page=$_GET["page"]

for display multiple page for one layout it mean i have index , it display layout and when i click on menu go to about us the index url = index.jsp?page=about in PHP when i declare $page above and next step i do

    Switch($page){
case 1:about 
include 'aboutus.php'
 case 2:news 
include 'news.php'
}

How can i do it ? How jsp can do the same way php to display multiple page in 1 layout

A: 

Use jsp:include.

<jsp:include page="/WEB-INF/${param.page}.jsp" />

And pass ?page=news or ?page=about, etc as parameter. The ${param.page} prints the outcome of request.getParameter("page"). You can prevent direct access to JSP files (by entering URL in browser address bar) by placing JSP files in /WEB-INF folder.

See also:

BalusC
A: 

Hello,

nowadays you use "templates" of Java Server Faces (JSF) for this approach. When you use JSP, you actually don't use the same concept as in PHP. You'd better use the MVC concept. But to answer your question, you could probably achieve this with the include tag http://java.sun.com/products/jsp/tags/11/syntaxref1112.html and control it with JSTL: http://www.java2s.com/Code/Java/JSTL/JSTLiftag.htm

Bevor