Write a search engine friendly article SEO page-class _jsp programming

Source: Internet
Author: User
Tags int size rowcount

Using dynamic programs such as jsp/php/asp to generate pages how to search engine friendly? You may want to use Url_rewrite. However, it is best to let the same URL at any time corresponding to the content of the page is the same or similar. Because the search engine does not like the page content is always changing URLs.

A general blog post needs to display the newly published article in front of it, so you will use an "ORDER BY ID DESC" SQL statement to query a page containing more than one article. For example, the following is in Java+mysql:

Public article[] Getarticlearray (int from, int size) {
article[] Article = new Article[0];
String query = "SELECT * from Blog ORDER by DESC ID LIMIT" + from + "," + size;
try{
ResultSet rs = st.executequery (query);
Rs.last ();
Size = Rs.getrow ();
Article = new Article[size];
Rs.beforefirst ();
for (int i=0; Rs.next (); i++) {
Article[i] = new article (
Rs.getint ("id"), rs.getstring ("Time"),
Rs.getstring ("name"), Rs.getstring ("blog")
);
}
Rs.close ();
}catch (Exception e) {
System.out.println (e);
}
return article;
}

This is one of our SEO page-class Myseopager methods. If we want to display the first page, we use Getarticlearray (0,10) to query the latest published 10 articles.

What's wrong with that? The problem is that when you add an article, all of the original pages change. In order for Getarticlearray (0,10) to display the same article for each query, you should let Getarticlearray (0,10) display the 10 newly published articles. We can change our paging class like this. Deleting the pages with the content that will affect the page, the more new articles you delete, the larger the page changes generated.

Public article[] Getarticlearray (int from, int size) {
article[] Article = new Article[0];
String query = "SELECT * from blog order by ID LIMIT" + from + "," + size;
try{
ResultSet rs = st.executequery (query);
Rs.last ();
Size = Rs.getrow ();
Article = new Article[size];
Rs.beforefirst ();
for (int i=0; Rs.next (); i++) {
Article[i] = new article (
Rs.getint ("id"), rs.getstring ("Time"),
Rs.getstring ("name"), Rs.getstring ("blog")
);
}
Rs.close ();
}catch (Exception e) {
System.out.println (e);
}
return article;
}

We also need to get the number of articles in the database, so add one more method.

public int Getarticlecount () {
int rowcount = 0;
String query = "SELECT COUNT (*) as rowcount from Ideabook";
try{
ResultSet rs = st.executequery (query);
if (Rs.next ()) {
RowCount = Rs.getint ("rowcount");
}
}catch (Exception e) {
System.out.println (e);
}
return rowcount;
}

We now display the latest 10 articles in the JSP page.

int start =-1;
Myseopager pager = new Myseopager ();
int artcount = Pager.getarticlecount ();
try{
Integer.parseint (Request.getparameter ("Start"));
}catch (Exception e) {
start = artcount-10;
}
if (Start > artcount-10) start = artcount-10;
if (Start < 0) start = 0;

Article art = Pager.getarticlearray (start, 10);
Do something and art here.
int previous = start + 10; To the start value of the previous page
int next = start-10; To the start value of the next page

In this way, whether or not the content of the generated page changes is related to whether you deleted the first published article. As long as you do not delete the article, showblog.jsp?start=0 with this parameter of the URL corresponding to the page does not change. As long as you delete the nth article, then start< (n-pagesize) The corresponding page does not change. You add articles only to affect the first page.

This method was used in the Ideabook message I wrote.

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.