Combined Use of El and jstl in J2EE

Source: Internet
Author: User

The example here is just a simple servlet + JSP and does not use a framework. If struts is used, it only needs to comply with the Action Standard in struts, or simply replace it with the struts tag.

 

Tomainaction

Public class tomainaction extends httpservlet
{
Private iboarderdao boarddao = new boarddaoimpl ();
Private itopicdao topicdao = new topicdaoimpl ();
Private iuserdao userdao = new userdaoimpl ();

Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception
{
// Plate list
List <board> boards = boarddao. getallboard ();
List <integer> COUNT = new arraylist <integer> ();
List <user> Users = new arraylist <user> ();
List <topic> lasttopic = new arraylist <topic> ();

If (null! = Boards)
{
For (board B: boards)
{
// Number of replies
List <topic> topic = topicdao. gettopicbyboardid (B. getborderid ());
If (null! = Topic)
{
Int num = topic. Size ();
Count. Add (Num );
}
Else
{
Count. Add (0 );
}

// Latest update
Topic T = topicdao. getlasttopic (B. getborderid ());
Lasttopic. Add (t );

// Author of the latest update
User u = userdao. getuserbyuid (T. getuid ());
Users. Add (U );
}

Request. setattribute ("Boards", boards );
Request. setattribute ("count", count );
Request. setattribute ("users", users );
Request. setattribute ("lasttopic", lasttopic );

Requestdispatcher Dis = request. getrequestdispatcher ("Main. jsp ");
Dis. Forward (request, response );
}

}

Public void dopost (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception
{
This. doget (request, response );
}

}

 

Main. jsp

<Body>
<Div id = "Container">
<Div id = "divlogin">
<JSP: Include page = "checuser. jsp"> </jsp: Include>
</Div>
<Div class = "nav">
<Div align = "Left" style = "font-weight: bold"> </div>
</Div>
<Table width = "100%" border = "3" bordercolor = "# d0e3ff"
Style = "font-size: 12px">

<Tr style = "background-color: # f3f8ef">
<TD Height = "22" colspan = "2" class = "noborder">
& Nbsp;
</TD>
<TD width = "11%" style = "border: 0; font-size: 12px">
Number of senders
</TD>
<TD width = "21%" style = "border: 0; font-size: 12px">
Latest update
</TD>
</Tr>

<C: If test = "$ {requestscope. boards! = NULL} ">
<C: foreach Var = "B" items = "$ {requestscope. Boards}" varstatus = "status">
<Tr>
<TD width = "6%" Height = "68">
& Nbsp;
</TD>
& Lt; TD width = "67%" & gt;
<Div align = "Left" class = "bluespan">
& Nbsp;

& Nbsp;
<A href = "tolistaction? Boardid =$ {B. borderid} ">$ {B. bordername} </a>
</Div>
</TD>
<TD>
$ {Requestscope. Count [status. Index]}
</TD>
<TD>
<Br/>
<P align = "Left">
$ {Requestscope. lasttopic [status. Index]. Title}
</P>
<Br/>
<P align = "Left">
$ {Requestscope. Users [status. Index]. Username}
</P>
<Br/>
<P align = "Left">
Modification time:
<Br>
$ {Requestscope. lasttopic [status. Index]. modifytime}
</P>
</TD>
</Tr>
</C: foreach>
</C: If>

</Table>

<Div id = "divcopy">
& Copy; xy-
</Div>
</Div>
</Body>

 

Checuser. jsp

<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "C" %>

<C: If test = "$ {not empty sessionscope. uinfo}">
<Span style = "color: Blue"> welcome:$ {Sessionscope. uinfo. Username}</Span>
<Span style = "color: Blue"> <a href = "gobackaction"> exit </a> </span>
</C: If>
<C: If test = "$ {empty sessionscope. uinfo}">
<Span style = ""> <a href = "tologinaction"> logon </a> </span>
</C: If>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.