Pergunta

I'm beginner in Servlets/JSP and now trying to do a little web-project but faced some issues which I can't solve. I'd like to ask you to give an idea of correct structure of the project (see the image). enter image description here

The main part of its project is couple of tables with editable data which is sent through servlet to DB. Rows can be added and deleted from table as same as frоm DB. I have the list of contractors also - by clicking on each I have relevant tables with data. I consider the following structure: each row in the table (Orders/Invoices) is a form which is submited and sent to the servlet when the data is entered and saved in DB. It is clear for me. I don't know how to make request to a servlet when I click on any contractor from the list to get in response the relevant table. (I tried to make it by XMLHttpRequest but it doesn't work properly). More over, If I understand it correct, the response should be in JSP which create page with relevant table for shosen contractor. Is it possible to get JSP response by using Ajax?) Browsing stackoverflow to find needed answers I got that the best way is to use jQuery (both for editable table and communication with server) but as I said I'm newcomer and would like to pay the most attention to java/servlet/jsp/jdbc in the first place and only then come to front-end technologies. I would appreciate a lot for ideas regarding the structure of the project.

Foi útil?

Solução 2

Is it possible to get JSP response by using Ajax?

Yes, the response of the AJAX call will be the content of the DIV that you want to update. In your case, when you click contractor # 3 for example, the table will be updated. So your AJAX call will hit a servlet which will forward to a JSP. JSP will return the table content.

<div id="orders">

JSP return content here.... orders table thing for the chosen contractor. 

</div>

JSP will have content like.

<table>
<tr><td>${"param1"}</td><td>${"param2"}</td></tr>
</table>

Do not use XMLHttpRequest directly. If you are allowed to do so, use jQuery. Disclaimer: I have not tried this. Please check exact syntax etc. I am trying to help you get started.

Outras dicas

Now probably nobody create applications in raw Servlets/JSP. Tables, lists, buttons and other components you have out of the box in JSF. IMHO best library for that is Primefacs. If you not like JSF, try GWT, Vaadin. If i can give you advice try this project schema JSF(presentation layer) ->EJB/Spring(service layer) -> Hibernate to persist data. Of course you may do this in JSP and XMLHttpRequest but for what? It's not effective, better and faster approach, is writing software in higher abstraction level.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top