Write a search engine-friendly Article SEO paging class

Source: Internet
Author: User

How are pages generated by dynamic programs such as jsp, php, and asp friendly to search engines? You may want to use url_rewrite. However, it is recommended that the content of the page corresponding to the same website address be the same or similar at any time. Because the search engine does not like the web site where the page content is always changing.

Generally, blog posts need to display new posts in front of them. Therefore, you can use SQL statements similar to "order by id desc" to query multiple articles on one page. For example, 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 a method in our SEO paging class MySEOPager. To display the first page, use getArticleArray () to query the latest 10 articles.

What's the problem? The problem is that after you add an article, all the original pages have changed. In order for getArticleArray () to display the same article for each query, getArticleArray () should display the first 10 new articles. We can modify our paging class in this way. Deleting and will affect the content of the page. The more you delete the new article, the larger the page that is 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 we need to add another 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;
}

Now we will display the latest 10 articles on 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 with art here.
Int previous = start + 10; // start value uploaded to the previous page
Int next = start-10; // The start value uploaded to the next page.

In this way, whether the content of the generated page changes is related to whether you have deleted the first published article. As long as you do not delete the article, showblog. jsp? Start = 0 the page corresponding to the URL with this parameter does not change. As long as you delete the nth article, the page corresponding to start <(n-pagesize) does not change. Only the first page is affected when you add an article.

This method is used in the ideabook message book 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.