How to solve 199 Employees Web App using JAVA? Give me a roadmap please

Back to General discussions forum

LotvinSergey     2016-03-14 20:46:56
User avatar

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?

Mohamed Aziz     2016-03-15 07:25:26
User avatar

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 ?

LotvinSergey     2016-03-15 08:25:25
User avatar

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.

Vladimir_V     2016-03-17 13:43:52

Олег привет! У меня такая же проблема с этой задачей. Попробуй это http://rutracker.org/forum/viewtopic.php?t=4935421 Если что пиши какие успехи :)

LotvinSergey     2016-03-20 17:17:20
User avatar

Спасибо, качаю! (на самом деле я Сергей, а вот зарегил меня друг и выбрал почему-то такой псевдоним. И теперь я не могу его поменять, пока не решу более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?

Quandray     2016-03-20 19:45:27
User avatar

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

Vladimir_V     2016-03-20 20:06:04

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

LotvinSergey     2016-03-21 06:45:19
User avatar

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.

Vladimir_V     2016-03-21 06:59:20

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

LotvinSergey     2016-03-21 07:56:41
User avatar

OK!

  1. You have to register on openshift and do all these actions get start
  2. As for me, I did next step - go to applications page https://openshift.redhat.com/app/console/applications
  3. Add application - Tomcat and then MySQL cartridge and phpMySQL admin
  4. Wait until your app will be created
  5. Then click to your app name and you are on your App admin page. You'll find there Source Code and Want to log in to your application? link.
  6. Start NetBeans
  7. Go to Service tab
  8. Right click Cloud and click Add cloud
  9. Choose OpenShift by Red Hat
  10. Enter login like YourName@yourEmail.ru and pass. Click Finish
  11. go to Servers node, click OpenShift by Red Hat. Wait. You'll see your up.
  12. Cursor on your app. Go to Team menu, Git Clone Use also this information, click links for pictures in the question credentials for repository at ssh
  13. Wait until you'll see The project cloned. Would you like to open? Click - yes.
  14. Then you'll see your project in Projects tab.

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.

LotvinSergey     2016-03-21 08:01:29
User avatar

+ 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.

Vladimir_V     2016-03-21 08:16:54

Thanks a lot for such comprehensive information :) Hopefully i can manage it :)

LotvinSergey     2016-03-21 09:03:46
User avatar

do not hesitate to ask... :)

Vladimir_V     2016-03-21 09:45:31

and you do not hestiatate to ask too :) But write directly on facebook :) Thanks

Quandray     2016-03-21 13:00:32
User avatar

Sorry Sergey, this sounds like a simple problem that is difficult to solve using Java. I just wrote a few (34) lines of perl.

LotvinSergey     2016-03-21 19:11:14
User avatar

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?

LotvinSergey     2016-03-24 21:08:13
User avatar

Well, i've done it eventually. Thanks to guys helped me here

Please login and solve 5 problems to be able to post at forum