从MySQL数据库打印日历[JSP / Servlet]

时间:2021-07-06 11:48:30

First of all, sorry for my english, as it's not my native language..

首先,对不起我的英语,因为这不是我的母语。

For a school project i'm trying to develop a site listing some student parties, that we insert into a mysql database via a form. Now, what i'm trying to do is print the parties in a table to make a calendar-like.

对于一个学校项目,我正在尝试开发一个列出一些学生派对的网站,我们通过表单插入到mysql数据库中。现在,我正在尝试做的是在一张桌子上打印各方以制作日历。

I've searched on google (which led me on some topics here) and i tried, but my code isn't working, and i can't figure why ...

我在谷歌搜索(这导致我在这里的一些主题),我试过,但我的代码不工作,我无法理解为什么...

If someone could help me, it would be really appreciated !

如果有人可以帮助我,我将非常感激!

My class Soiree :

我的班级Soiree:

public class Soiree {
private String organisateurs;
private String local;
private String heureDebut;
private String jour;

public void setOrganisateurs(String organisateurs){
    this.organisateurs = organisateurs;
}

public String getOrganisateurs(){
    return organisateurs;
} //And the rest of the setters/getters

My servlet Calendrier.java

我的servlet Calendrier.java

public class Calendrier extends HttpServlet {

public static final String VUE = "/WEB-INF/calendrier.jsp";
private static final String DB_URL ="jdbc:mysql://localhost:3306/projetweb";
private static final String DB_USER = "root";
private static final String DB_PWD = "qsd123qsd";
private static Connection conn;
public static final String ATT_SOIREE = "soiree";


public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

    ArrayList<Soiree> soirees = new ArrayList<Soiree>();

       try{
            try{
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection(DB_URL,DB_USER,DB_PWD);
                conn.setAutoCommit(true);
            }catch (Exception e){
                System.out.println("Connection failed" +e.toString());
            }

            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery("SELECT organisateurs,local,jour,heure from soirees order by jour");


            while(rs.next()){
                Soiree soiree = new Soiree();
                soiree.setOrganisateurs(rs.getString("organisateurs"));
                soiree.setLocal(rs.getString("local"));
                soiree.setHeure(rs.getString("heure"));
                soiree.setJour(rs.getString("jour"));
                soirees.add(soiree);
            }


       }catch (Exception e){
            System.out.println("Exception in verifyPasswd " + e.toString());

        }
        request.setAttribute(ATT_SOIREE, soirees);
            /* Transmission de la paire d'objets request/response à notre JSP */
            this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );

}

}

And finally my Calendrier.jsp (only the relevant part to print) :

最后我的Calendrier.jsp(只打印相关部分):

<c:foreach var="soirees" items="${soirees }" >
                <c:out value="${soirees.organisateurs }" />
                <c:out value="${soirees.local }" />
                <c:out value="${soirees.heureDebut }" />
                <c:out value="${soirees.jour }" />
            </c:foreach>

PS: Sorry for the long post !

PS:很抱歉很长的帖子!

1 个解决方案

#1


0  

Try adding s to ATT_SOIREE

尝试将s添加到ATT_SOIREE

public static final String ATT_SOIREE = "soirees";

and remove the space to match the corresponding EL variable (along with all the other spaces)

并删除空格以匹配相应的EL变量(以及所有其他空格)

<c:foreach var="soiree" items="${soirees}" >
        ${soiree.organisateurs}<br>
        ${soiree.local}<br> 
        ${soiree.heureDebut}<br>
        ${soiree.jour}<br>
</c:foreach>

#1


0  

Try adding s to ATT_SOIREE

尝试将s添加到ATT_SOIREE

public static final String ATT_SOIREE = "soirees";

and remove the space to match the corresponding EL variable (along with all the other spaces)

并删除空格以匹配相应的EL变量(以及所有其他空格)

<c:foreach var="soiree" items="${soirees}" >
        ${soiree.organisateurs}<br>
        ${soiree.local}<br> 
        ${soiree.heureDebut}<br>
        ${soiree.jour}<br>
</c:foreach>