0

I want to have a forum in my website project in school. i don't have any idea. may anyone help me suggesting some examples. it is like daniweb forums. i want to save the topics in the database and retrieve it as a link. i dont know how to do that in jsp code. can anybody help me?? i really need help.

God bless you .

6
Contributors
24
Replies
112
Views
5 Years
Discussion Span
Last Post by angela_8
Featured Replies
  • alright well i am definitly not gonna give you any code as it is for a school project, but ill help you with the general idea and then you can come back with some actual work to get further help. first off, you do not want to create a forum … Read More

1

alright well i am definitly not gonna give you any code as it is for a school project, but ill help you with the general idea and then you can come back with some actual work to get further help.

first off, you do not want to create a forum that is "complete" with all the features and stuff, and i am also going to assume that you are already handling login sessions with username and passwords.

you will need at least 2 tables, 1 for the threads and 1 for the posts, more if you plan to have many forum categories. but for a simple single forum with threads and posts, thats the minimum you need... threads and posts.

on you main "forum.jsp" page, you will get all threads in a dataset, and simply loop through them adding <a> tags to a "thread.jsp?threadID=xxxxxx" where xxxxx will be the threadID from your Thread table.

then in thread.jsp , you will have to fill 2 datasets. the first one with all the info about the thread itself. (possibly also the contents of the 'original post' depending if you saved it in the thread structure or consider it as a post like any others) , and the second dataset will have all posts that belong to that thread.

then you simply print out all the html for the page, the thread title and stuff from dataset #1 , then you loop through all the posts in dataset #2 and print the html for the posts.

finish with a simple button to add a new post to this thread which would link to like "newPost.jsp?threadID=xxxxxx" and there you can have the input form for adding a row to your posts table!

and you have yourself a very basic forum :)

0

i really appreciate for your help. thank you so much. i humbly say that i am not so knowledgable about threading but i will study. i hope i can cope up because i will pass my project this may 15.

can you give me an example of threading and the one you said the threadID? if it's okay to you.

i really need help sir. thankyou so much for giving me ideas.
God bless.

0

i just want to have a post that will be inputted by the user and anybody can comment. i want a basic forum like that. is that okay?

0

that is what a "forum thread" is , there is nothing in this about "threads" per say.

a "thread" in a forum is the sum of the initial post and the posts that users added.

for example, you started this "thread" when you posted your question, and now my first post , your 2 other posts and this post, were added to this "thread" , its basicly just what keeps all the posts in the database organised in discussions. Im sorry if this is not very clear! Are you getting the difference between "forum thread" and a "programming thread" ?

0

now, i understand. i misinterpreted it sir. sorry. i am thinking of programming thread and not the forum thread.

my only problem is how to link those posts and retrieve its comments. i am confused how to get it. example, when i clicked one of the posts then it will be directed to another page and display the post title and its comments.

i don't know how to do that. can you give me an idea sir?

really thankyou for helping me. i appreciate it a lot. God bless you more. thankyou for being kind..

0

its as simple as a <a> tag in your html !

you have forum.jsp :
here you will retrieve all threads from database, loop through them with java and create <a> tags for each thread!

        <% for(...){ %> 
            <a href="thread.jsp?threadid=<%= resultSet.getInt("Thread_ID") %>"><%= resultSet.getString("Thread_Title") %></a>
        <% } %>

and then you have thread.jsp :
here you will retrieve the argument in the query string ("threadid") and create a result set will all infor about that specific thread, and create your page with that result set

Edited by Philippe.Lahaie: code "tags"

0

sir here is some of my code. how can i inser in a primary key and auto increment column in mysql. before the "topic" there. because i have a primary key "Thread_id" sir. i need help sir. thankyou . God bless.

<%
    String url = "jdbc:mysql://localhost/Login";
    String userid = "root";
    String passToTheDatabase = "root";
    String topic = request.getParameter("topic");
    int count = 1;

    try { 
        Class.forName("com.mysql.jdbc.Driver"); 
    }
    catch(java.lang.ClassNotFoundException e) { 
    System.err.print("ClassNotFoundException: " + e.getMessage()); 
    }

    try {
        Connection con = DriverManager.getConnection(url, userid, passToTheDatabase);
        Statement stmt;
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
        stmt.executeUpdate("Insert into topic values('"+topic+"')");


        stmt.close();
        con.close();
    }

    catch(SQLException ex)
    {
      System.err.println("SQLException: " + ex.getMessage()); 
    }

    response.sendRedirect("forums.jsp");



%>
0

thankyou so much sir for helping. i have another problem sir. if it is okay to you if i ask more.

how can i fix the mysql syntax when i will input that has a character of this " ' " or the apostrophe. because if i input like " there's " or something like that . it will be an error.

i need help sir. thankyou. God bless :)

0

when i used this is sir. i got and error. it says:

column description not found.

Connection con = DriverManager.getConnection(url, userid, passToTheDatabase);
        PreparedStatement pstmt = con.prepareStatement("Insert into topic(topic,description) values('"+topic+"','"+description+"')");
    pstmt.close();

        con.close();

Edited by diafol: reapplied code tags

0

check the tutorial again, you should not directly input the variables into the prepared statement, you put some "?" instead where the variables will go, then you use "setString()" method or "setInt()" etc~ , this will sanitize your inputs.

also check your column names, the error you are getting is simply because there are no column named "description" int the "topic" table.

...Insert into topic(topic,description)...

Edited by Philippe.Lahaie: typo

0

thankyou sir.. i learned a lot from you. i hope i can contact you always when i have some other problems. thankyou again. God bless you more.

0

any time! although im far from an expert on jsp haha

you should set the thread as solved if you dont have any other questions on this subject!

also if any answer was particulary helpful a little reputation is always appreciated :)

0

thankyou so much sir. i am seeing you as an jsp expert. hahaha.

there is another thing that i am having problem. when i input a text like this:

"The quick brown fox jumped over the lazy dogs.
The quick brown fox jumped over the lazy dogs. "

i inputted like this in the textarea. but when i retrieve it from the database it will just look like this:

"The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs."

I don't know how to store to database like that. because i noticed that when i press enter and then a new line but when it is stored in the database, it doesn't include the new line inputted. it's like that it ignores the new line input.

what is the solution about this sir? can you help me?

0

im am not 100% sure what would be causing your newlines to not be saved correctly but from a quick google search it simply seems sql does not consider \n as a new line, perhaps before inserting the string, format it to replace all "/n" with "char(13)" according to this post

try this and let me know if it works! :)

0

i got the code sir and it is just so simple. i google it. it looks like this:

String comment = request.getParameter("comment").toString().replaceAll("\n","<br/>");

thankyou so much sir for all the help :))
i will contact you again when i have problems. if it is okay? hehe. thankyou again. God bless you always :))

0

I have a jsp page with sql statement of perticular table and moving the result to jsp page varaibles but i want to move a value of a single filed from other table what would i do how will i move that into the current page

-1

hi sir am gonna develop a web application project for forum..for that i need the database maintainance about the forum realted primary key and how to maintain the cookiee and session for all the user..

0

like my last post on this thread...

please start a new thread about your issues instead of reviving year old threads. thank you.

0

this seems nice. i'm new at jsp and looking forward to using it on my new forum..

0

plz help me I want to have a forum in my website project in school. i don't have any idea. may anyone help me suggesting some examples to create relpy page .this codes i m try but it not check null value plz plz fast reply .

<%@page import="java.sql.*"%>
<%@page import="java.io.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
          <%
        String id=request.getParameter("id");
String answer=request.getParameter("answer");
    Class.forName("com.mysql.jdbc.Driver");
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/registation?zeroDateTimeBehavior=convertToNull","root", "isha");
    Statement st = con.createStatement();

        ResultSet rs;

                     rs=st.executeQuery("select answer1 from dicussion" ) ; 

     if(rs.wasnull()){
        //<c:if test="${empty str1}">

           int i =st.executeUpdate("update dicussion  set  answer1 ='"+answer+"' where question_id ='"+id+"'");
    if (i > 0) {
        //session.setAttribute("userid", user);
        response.sendRedirect("welcome.jsp");
       // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
    } 
    }
   else {
          rs=st.executeQuery("select answer2 from dicussion" ) ; 

      if(rs ==null){

       // response.sendRedirect("p.jsp");
        int j =st.executeUpdate("update dicussion  set  answer2 ='"+answer+"' where question_id ='"+id+"'");
    if(j > 0) {
        //session.setAttribute("userid", user);
      response.sendRedirect("welcome.jsp");
       // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");

      }
      }
      else {

          int k =st.executeUpdate("update dicussion  set  answer3='"+answer+"' where question_id ='"+id+"'");
       if (k  > 0) {

        //session.setAttribute("userid", user);
        response.sendRedirect("welcome.jsp");
       }

       else{

        response.sendRedirect("p.jsp");
       }

    }
     }

%>

    </body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.