Back to General discussions forum
Hello! I can't understand which way I have to go in order to solve "Employees Web App" with JAVA? Shall I read JSP/Servlet books? Or HTML? In eaxmple, there we can see when we add new name the code of the page is changed.
To the list (html):
<ul style="list-style-type:none">
<li>Mr Scrooge</li>
</ul>
We add NewNameHere and then the list looks like (html):
<ul style="list-style-type:none">
<li>Mr Scrooge</li>
<li>NewNameHere</li>
</ul>
It means that JSP code must be changed, am I right? Could one advise what to read on this topic? Maybe JSP/Servlet can't help me with this task?
You can write a little python or php script to solve this simple task. the problem text also suggsts that you use a database (but you can do it without one).
Also as I have noticed It won't submit if you submit you machine ip, (I had to deploy my dirty python code (I used bottle for this task) on python anywhere, it seems that the problem setters wants us to see the real world and deploy the code online), so is there a free JSP host ?
Hello, Aziz! But I need it to be done using JAVA. The host for JAVA is https://www.openshift.com/ I know the task is not so complicated, but I have to train JAVA and using DataBase is also good for practice. But I can't understand how to solve the task with JSP/Servlet...even in which book I can find the answers.
Олег привет! У меня такая же проблема с этой задачей. Попробуй это http://rutracker.org/forum/viewtopic.php?t=4935421 Если что пиши какие успехи :)
Спасибо, качаю! (на самом деле я Сергей, а вот зарегил меня друг и выбрал почему-то такой псевдоним. И теперь я не могу его поменять, пока не решу более124 задач :) ) Отвечу сам на свой вопрос, так как вроде бы разобрался. Отвечу на англицком, а удитория сайта интернациональна.
So, let me answer to my question: To solve this task you can use - JSP, Servlet, SQL (I used MySQL) and HTML dictionary. Here is my WebApp [Employees Web App Sergey L.] (http://caewa-sergeylotvin.rhcloud.com/index.jsp) I also used OpenShift in order to HOST my App and MySQL cartridge. In general - index.jsp is the main page. There I put all stuff like title, input form, buttons etc. When User enter text and click 'Add Employee' the Get starts to send data to servlet. All mappings are in the web.xml It means that index.jsp has form action="dbSelSrv.my" method="get" tag that run action and hand over the control to dbSelSrv.my who is servlet. Servlet get data using doGet method. Inside servlet I create object of a class, for example the class that make SELECT query, INSERT INTO etc. After all actions servlet can redirect back to index.jsp
response.sendRedirect("http://caewa-sergeylotvin.rhcloud.com/index.jsp");
or return new jsp with new SELECTed data
....
request.setAttribute("arrSize", dbObj.getArrSize());
RequestDispatcher view
= request.getRequestDispatcher("/index.jsp");
view.forward(request, response);
request.getRequestDispatcher("index.jsp").forward(request, response);
Also I shall mention, that JSP allow you to insert some JAVA code inside the page
<% out.println(request.getAttribute("arrSize")); %>
We can see that data from dbObj.getArrSize() goes to JSP through "arrSize"
All the information above is for my understanding and for all who doesn't know how to start. Moreover it is possible that I didn't got the idea correctly and it would be great if someone point to mistakes. By the by, I have a problem. The checker doesn't accept my solution. Wrong state after adding person #1: Expected 2 list elements, but found 1 As I think the problem is the checker send http://caewa-sergeylotvin.rhcloud.com/index.jsp?name=example
And then check http://caewa-sergeylotvin.rhcloud.com/index.jsp but the result page URL changed to http://caewa-sergeylotvin.rhcloud.com/dbSelSrv.my?name=example
And now I have no idea how to avoid the URL changing. Can someone help?
If your page is http://caewa-sergeylotvin.rhcloud.com/index.jsp
Calling http://caewa-sergeylotvin.rhcloud.com/index.jsp should display the page
Calling http://caewa-sergeylotvin.rhcloud.com/index.jsp?kill should clear all names except the company founder
Calling http://caewa-sergeylotvin.rhcloud.com/index.jsp?name=New+Name should add a new name
Serge Hi! One more questions for you. How did you upload your war file to RedHat or OpenShift whatever ? Acctully a heve a jsp file too, but i can not upload it OpeSnhift. Can you give me some links where a can see how to do it. Thans a lot
Quandray, that I understand. The problem is that if you use servlet your URL will change. Servlet name will be inserted in it. For user it is not a problem, but checker doesn't get it. And I have no idea how to avoid it with JSP/Servlet.
Vladimir_V, what IDE do you use? I use NetBeans and can tell you how to upload files with this IDE.
I use Ecplipse, but a know how to work with NetBeans too.So if you wold be so kind to help would be great :) I can find me via FaceBook, see the link from my profile. Thanks
OK!
You also have to install Git for NetBeans.
I'm sorry for confusing information, but I can't remember all steps and order. Please, try this and ask when you encounter a problem. I'll try to help.
+ when you install the Git for NetBeans, you will get all Git menu in the IDE. After you did some alterations in the code you have to click Commit button and then Push button.
Thanks a lot for such comprehensive information :) Hopefully i can manage it :)
do not hesitate to ask... :)
and you do not hestiatate to ask too :) But write directly on facebook :) Thanks
Sorry Sergey, this sounds like a simple problem that is difficult to solve using Java. I just wrote a few (34) lines of perl.
Well, for now I found that this can be solved with JSP/Servlet but you cannot keep the URL constant. It is because all work is on the servlet part not on the JSP. In order to stay with the same URL you have to use client-side scripting. It means all work must be done by JSP. Are my reasoning right? And I have to find out what shall I use to force JSP to behave like dynamic page. Any idea?
Well, i've done it eventually. Thanks to guys helped me here