I used JSP/Servlet and OpenShift as a HOST. My solution
The problem is when I add new name the URL is changed from http://caewa-sergeylotvin.rhcloud.com/index.jsp to http://caewa-sergeylotvin.rhcloud.com/dbSelSrv.my?name=NewNameExample. index.jsp transform to dbSelSrv.my where dbSelServ.my is my Servlet.
How can I avoid this changes? Because for checker I need it work like that:
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
Can someone help?
p.s.: I need to solve it with JAVA, not AJAX or php or other.
You also shouldn't send commands as request parameters. Make separate actions for separate commands. index.jsp shouldn't be a catch-all.
That means to delete all names, you could POST to an URL like http://caewa-sergeylotvin.rhcloud.com/clear-all.jsp, and to add a new name you could POST to http://caewa-sergeylotvin.rhcloud.com/add.jsp
when first request the page, than exactly
when Add new Employee.
You must change the action of your form element to action="index.jsp", but if you need to send data using query parameters (which is a BAD idea), then you can't prevent the form from also adding other inputs (like the submit button) to the query parameter string.
Bear Bibeault wrote:Is this an academic exercise where you are limited to doing this in this way, or real production code?
It's not an academic exercise . But I'm afraid I could be limited by the HOST (but looks like openshift allow to use Spriong) - at first, and by my knowledge as a second. I'm newbie in JAVA.
Bear Bibeault wrote:Then why are you trying to keep the URL constant in the first place? It's not a reasonable nor customary thing to do. It sounds like the sort of silly thing an academic exercise would ask someone to do so they "can figure out how to do it", but it's not something one would see in a real-world erg app. So what's the actual goal here?
Because the checker works. checker is some kind of program, that start with http://blablabla/index.jsp then add names using GET http://blablabla/index.jsp?name=NewName . But my Web App works with servlet and index.jsp changes to MyСorrespondingServlet.lol and URL from
but checker can't know about MyСorrespondingServlet.lol
In your case, you only have a GET request to show the employees, with the special case that it can change the state of the application if the request includes the parameters kill or name. NEVER do this in real life.
The code you need is simple enough that you probably don't have to include an entire MVC framework, but in a real world application I would.
What you need to do now is edit my code example so that the servlet retrieves a list of employees, sets it as an attribute in the request, and forwards the request to the JSP. All the JSP should do is display the list of employees. It shouldn't interact with the database in any way.
Don't worry about killing or adding employees yet, just show us that you can forward data from a servlet to a JSP.
ItDoesntWorkIsUseless. Please tell us exactly what's happening. Here's what I have, and it works just fine:
I then browse to http://localhost:8080/example/index.jsp (/example is my application's context path), and I get a lovely "Hello World!" message.
I very much prefer to use /employees as the URL pattern for my servlet though, so I can browse to http://localhost:8080/example/employees?name=John%20Doe.
Many many thanks, Stephan van Hulst!