14.5 compile the JSP page of the News Publishing System

Source: Internet
Author: User

 

14.5 compile the JSP page of the News Publishing System

Compile Its JSP page based on the news publishing system designed above.

14.5.1 show. jsp

The page is stored in the WEB-INF/JSP to display published news and display according to the news category. Place the news title in the map array to establish the correspondence between the news category ID and news title. First, the news category is displayed cyclically. At the same time, each news category is displayed, and the news title corresponding to the news category is displayed cyclically. The show. JSP code is as follows:

<% @ Page contenttype = "text/html; charset = GBK" %>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"

Http://www.w3.org/TR/html4/loose.dtd>

<% @ Page import = "Java. util. *, Com. GD. util. *, Com. GD. VO. *, Com. GD. po. newstype, Com. GD. po. new "%>

<HTML>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Title> display page of news publishing </title>

<Style type = "text/CSS">

<! --

. Style1 {font-family: ""}

-->

</Style>

</Head>

<%

List listnewstype = (list) request. getattribute ("listnewstype ");

Map mapnews = (MAP) request. getattribute ("mapnews ");

%>

<Body>

<Table width = "100%" Height = "100%" border = "1" cellpadding = "0" cellspacing = "0">

<%

For (INT I = 0; listnewstype! = NULL & I <listnewstype. Size (); I ++ ){

%>

& Lt; tr Height = "100%" & gt;

<TD Height = "20"> <strong> <% = (newstype) listnewstype. Get (I). GetType () %> </strong> </TD>

<TD> <strong> <% = (newstype) listnewstype. Get (I + 1). GetType () %> </strong> </TD>

</Tr>

& Lt; tr Height = "100%" & gt;

<TD Height = "150" type = "codeph" text = "codeph"> <ol>

<%

List newsheads = (list) mapnews. Get (newstype) listnewstype. Get (I). GETID ()));

For (Int J = 0; newsheads! = NULL & J <newsheads. Size (); j ++ ){

%>

<Li> <% = (new) newsheads. Get (j). getcontent () %> </LI>

<% }%>

</OL> </TD>

<TD> <ol>

<%

Newsheads = (list) mapnews. Get (newstype) listnewstype. Get (++ I). GETID ()));

For (Int J = 0; newsheads! = NULL & J <newsheads. Size (); j ++ ){

%>

<Li> <% = (new) newsheads. Get (j). getcontent () %> </LI>

<% }%>

</OL> </TD>

</Tr>

<Tr Height = "100%" style = "border-top-width: 1">

<TD Height = "15" style = "border-top-width: 1 "> <Div align =" right "class =" style1 "> more </div> </TD>

<TD style = "border-top-width: 1"> <Div align = "right" class = "style1"> more </div> </TD>

</Tr>

<% }%>

</Table>

</Body>

</Html>

Code Description: Map mapnews = (MAP) request. getattribute ("mapnews"). The content of each news class is displayed cyclically through map.

14.5.2 release news page release. jsp

This page is stored in the WEB-INF/JSP, mainly through the form to submit the user to fill in the news title and content and publisher, here added a helper class newsutil. Java, mainly used to get the current date. The code for release. jsp is as follows:

<% @ Page contenttype = "text/html; charset = GBK" %>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"

Http://www.w3.org/TR/html4/loose.dtd>

<% @ Page import = "Java. util. List, Com. Gd. util. *, Com. Gd. VO. User, Com. Gd. Po. newstype" %>

<HTML>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Title> Publish a news page </title>

<Style type = "text/CSS">

<! --

. Style1 {

Font-size: large;

Font-weight: bold;

}

-->

</Style>

</Head>

<%

List newstypes = (list) request. getattribute ("newstypes ");

User user = (User) request. getattribute ("user ");

%>

<Body>

<Form name = "form1" method = "Post" Action = "/mynews/release. Do">

<Table width = "100%" Height = "160" border = "1" cellpadding = "0" cellspacing = "0">

<Tr>

<TD Height = "17" colspan = "2"> <Div align = "center" class = "style1"> Publish news </div> </TD>

</Tr>

<Tr>

<TD width = "126" Height = "19"> <strong> News Title </strong> </TD>

<TD width = "560"> <input name = "head" type = "text" size = "100%"> </TD>

</Tr>

<Tr>

<TD Height = "73"> <strong> news content </strong> </TD>

<TD> <p>

<Textarea name = "content" Cols = "100%" rows = "30"> </textarea>

</P>

</TD>

</Tr>

<Tr>

<TD Height = "19" colspan = "2"> <strong> Release Date: </strong> <% = newsutil. getcurrentdate () %>
<Strong> publisher </strong>: <% = user. GetUserName () %> <strong> News Category </strong>:

<Select name = "newstype">

<%

For (INT I = 0; newstypes! = NULL & I <newstypes. Size (); I ++ ){

Newstype = (newstype) newstypes. Get (I );

%>

<Option value = '<% = newstype. GETID () %>'> <% = newstype. GetType () %> </option>

<% }%>

</SELECT> </TD>

</Tr>

<Tr>

<TD Height = "18"> & nbsp; </TD>

<TD> <input type = "Submit" name = "insert" value = "Submit">

<Input type = "Submit" name = "Update" value = "modify">

<Input type = "Submit" name = "delete" value = "delete"> </TD>

</Tr>

</Table>

</Form>

</Body>

</Html>

Code Description: newsutil. getcurrentdate (). Here, a helper class newsutil is added
Auxiliary methods of the mynews system, which are included in the package com. Gd. util.

14.5.3 user registration page Regedit. jsp

The page is stored in the WEB-INF/JSP, mainly through the form to submit the user name and password entered by the user. The example code of Regedit. jsp is as follows:

<% @ Page contenttype = "text/html; charset = GBK" %>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"

Http://www.w3.org/TR/html4/loose.dtd>

<HTML>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Title> user registration page </title>

</Head>

<Body>

<Form name = "form1" method = "Post" Action = "/mynews/Regedit. Do">

<Table width = "100%" Height = "251" border = "1" cellpadding = "0" cellspacing = "0">

<Tr>

<TD Height = "17" colspan = "2"> <Div align = "center"> <strong> Registered User </strong> </div> </TD>

</Tr>

<Tr>

<TD width = "18%"> <strong> User name: </strong> </TD>

<TD width = "82%"> <input type = "text" name = "username"> </TD>

</Tr>

<Tr>

<TD> <strong> password: </strong> </TD>

<TD> <input type = "password" name = "password1"> </TD>

</Tr>

<Tr>

<TD> <strong> Confirm Password: </strong> </TD>

<TD> <input type = "password" name = "password2"> </TD>

</Tr>

<Tr>

<TD colspan = "2"> <Div align = "center">

<Input type = "Submit" name = "Submit" value = "register">

<Input type = "reset" name = "Submit" value = "reset">

</Div> </TD>

</Tr>

</Table>

</Form>

</Body>

</Html>

14.5.4 Administrator Logon page login. jsp

The page is stored in the WEB-INF/JSP, mainly through the form to submit the user to fill in the user name and password, used to verify whether the user is filled in correctly. The sample code of login. jsp is as follows:

<% @ Page contenttype = "text/html; charset = GBK" %>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"

Http://www.w3.org/TR/html4/loose.dtd>

<HTML>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Title> Administrator Logon page </title>

</Head>

<Body>

<Form name = "form1" method = "Post" Action = "/mynews/login. Do">

<Table width = "100%" Height = "251" border = "1" cellpadding = "0" cellspacing = "0">

<Tr>

<TD Height = "17" colspan = "2"> <Div align = "center"> <strong> Administrator Logon </strong> </div> </TD>

</Tr>

<Tr>

<TD width = "18%"> <strong> User name: </strong> </TD>

<TD width = "82%"> <input type = "text" name = "username"> </TD>

</Tr>

<Tr>

<TD> <strong> password: </strong> </TD>

<TD> <input type = "password" name = "password1"> </TD>

</Tr>

<Tr>

<TD> <strong> Confirm Password: </strong> </TD>

<TD> <input type = "password" name = "password2"> </TD>

</Tr>

<Tr>

<TD colspan = "2"> <Div align = "center">

<Input type = "Submit" name = "Submit" value = "Logon">

<Input type = "reset" name = "Submit" value = "reset">

</Div> </TD>

</Tr>

</Table>

</Form>

</Body>

</Html>

14.5.5 error handling page error. jsp

This page is stored in the WEB-INF/JSP, mainly used to capture and display the exception information of the program. The sample code of error. jsp is as follows:

<% @ Page contenttype = "text/html; charset = GBK" %>

<HTML>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Title> error handling page </title>

<Style type = "text/CSS">

<! --

. Style1 {

Color: #000000;

Font-weight: bold;

}

. Style2 {color: # ff0000}

-->

</Style>

</Head>

<% Exception EX = (exception) request. getattribute ("exception"); %>

<Body>

<Table width = "100%" border = "1">

<Tr>

<TD colspan = "2"> <Div align = "center"> <strong> error message display </strong> </div> </TD>

</Tr>

<Tr>

<TD width = "22%" Height = "141"> <SPAN class = "style1"> error message: </span> </TD>

<TD width = "78%"> <SPAN class = "style2"> <% = ex. getmessage (); %> </span> </TD>

</Tr>

</Table>

</Body>

</Html>

To use this page, add the following code in the spring configuration document:

<Bean id = "exceptionresolver" class = "org. springframework. Web. servlet. handler. simplemapping-
Predictionresolver ">

<Property name = "exceptionmappings">

<Props>

<Prop key = "Java. SQL. sqlexception"> error </prop>

<Prop key = "Java. SQL. ioexception"> error </prop>

</Props>

</Property>

</Bean>

Code Description: As long as sqlexception exception or ioexception occurs, it will be connected to the/WEB-INF/
JSP/error. jsp.

Related Article

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.