Use JSP to do backstage management system

Source: Internet
Author: User

Suddenly very happy, nervous for several days of the project finally not so rush.

I am a slower than others to beat people, so must be more than others to pay a little more effort.

Today in the news to add the time to find that there is a lot of extensibility, but also can only be the brain has something, but do not know how to do (I hope not to forget, after the next study will be back to do this matter).

By the way, the mistake made today.

It was a long struggle to add news.

/**
* Get data read from the page
* @param request
* @return Individual news information
* @throws unsupportedencodingexception
  */
private News getnews (HttpServletRequest request) throws Unsupportedencodingexception {
request.setcharacterencoding ("UTF-8");
//read which topic ID the user chooses
String id = request.getparameter ("topic");
//Convert value to int type to topic entity class
Topic Topic = new Topic (Integer.parseint (ID));
//Title
String title = Request.getparameter ("title");
//Author
String author = request.getparameter ("author");
//Abstract
String Summary = request.getparameter ("summary");
//Content
String ncontent = Request.getparameter ("ncontent");
  
News news = new News (topic,title,author,summary,ncontent);
  
return news;
 }

/**
* Add News
*/
public void Addnews (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Boolean B = Ndi.addnews (getnews (request));
if (b) {
Selectnews (request, response);
}else{
Request.setattribute ("ErrorInfo", "News add failed!") ");
Request.getrequestdispatcher ("error.jsp"). Forward (request, response);
}
}

The following details why the acquisition was wrong.

The first step:

I first manually added data from the database to the table, and I found that I could. But cannot execute.

Step Two:

I modified the value in the news entity class to be added to the string instead of the contents of the page, and the result shows that there is an FK constraint. Still cannot be executed.

Step Three:

Finally know the wrong place, very happy. Then I changed the foreign key constraint that I built earlier.

T_news:id ==t_topic:id---> t_news:tid = = T_topic:id

Because I have associated the primary key in the two tables, I cannot execute it. Change the Subject ID column in the news table to correspond to the ID column in the topic table. It turns out that it still can't be executed.

Fourth Step:

and jump to the page, found that I did not give a drop-down menu name!!

Alas, I am a careless man. Then think of the teacher so-called to let the program find your drop-down box to give value, so give the ID.

That should be all right. The result is still not working.

Fifth Step:

Head of the dizzy, it seems that I really do not come out. Then he called the teacher and asked why. He glanced at it and said:

<%--want to get the value of SELECT, you need to give him a name. Remember: Using name instead of Id,id is unique and applies to css,name for background gain--%>

Oh, this is not the ID but name AH.
<select name= "topic" >
<c:foreach items= "${topiclist}" var= "topic" >
<option value= "${topic.id}"/>${topic.tname}
</c:forEach>
</select>

This project finally can see open, very happy. Look at the things you create, really happy.

Finally warned me that debugging is really important, English words really important, extracurricular knowledge is really important.

Use JSP to do backstage management system

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.