• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

display the log/output in JSP or HTML page

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I have a question and i would realllly appreciate it if someone can help me..

I have a web application, JSP+Servlet+Agent&Normal Java classes that will work in the background.
The code should do some process and show result to a user.. and for example ask you the user to select from a list an option, based on user's selection another process will take off.

Anyways.. now this interaction or the results that the java class will show to user, i have used System.out.println(); to show them to the user ...

I need them to be shown in a JSP or HTML and then the user can interact with it..

The issue is a java class call an html to pass a question or a result, and then take back an answer to same java class so it can be resumed working..
I have searched for an example but no luck!

I have tried something too, is that from the java class, i call a dynamic Servlet ( i would call it), which will be willing to take whatever question .. pass it to a jsp and take back the result to the java class.. but it didnt work too..

I would really appreciate it if someone can suggest something..

Thanks in advance,
Hend
 
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hend Ahmed,

use scriptlet in JSP page, i mean the coding part that you have done in .java file put all those inside scriptlet,
instead of using system.out.println() use out.prinlln(). (you need to use expressions)

read http://download.oracle.com/javaee/5/tutorial/doc/bnaou.html
also, you can easily pass parameter in JSP. eg http://www.jsptut.com/Sessions.jsp

 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply

So you mean that i should put like the whole java class in JSP scriptlet? Instead of using java classes?

I will try this but i'm not sure if the agents will work this way

Thanks,
Hend
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

debraj mallick wrote:
use scriptlet in JSP page, i mean the coding part that you have done in .java file put all those inside scriptlet,


Worst advice ever!

Do not use scriptlets in a JSP. That is a poor practice that has been discredited for over 9 years now.
 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have no other solution! do you suggest something else?

Please advise
 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, i didn't try it, but i believe it is not going to work ..

according to my project, a servlet initiate an object of a class which i call it Agents Engine that will create containers for agents and create a couple of agents.. Those agents will pull information from the database and provide it to the user in a form of results or a question .. (mostly will be questions or lists that the user will select one data)..

so the interaction between the agent and the user.. I can't put the code of agent in a JSP because when creating an agent i use some kind of statement like


i'm not sure if the jsp that will contain the agent code will be used as in the above statment


Please advise
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you really trying to accomplish? Putting logging statements out onto a page is a very strange and weird thing to want to do. What's your actual aim?
 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The agent will check the users profile and ask him if he booked a Hotel , for example..if No then will pull list of hotels.. Based on user's selection to a Hotel , profile will be updated..

This is what am asking about!how I can show these questions? Do you suggest something? I have put them to be shown in the console just to check if its working..

If I'm going to publish this web application on the web, there will be no console! How the user is going to see these questions and will be able to select something..

The agent is a java class, and it is in charge of firing these questions..?

I hope this clarify it
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well that has nothing at all to do with logging!

You are describing a simple and normal interaction in web applications. Perhaps you should start from the beginning and understand how HTTP and HTML interoperate?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTTP is a request/response model.

So each question/answer from the server has to be a request/response.

At its simplest you could use multiple jsp pages each one asking a question, and then submit the answer to a servlet, do the processing, and figure out which jsp to display next. So each time the user selects something, it will display a new JSP page.

More complicated, you could do an ajax style app which updates the current page using javascript (based on the server response) rather than reloading a brand new page.
This normally leads to a better user experience as it seems more responsive.



 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

Yes i know it does not have to do with the logging. Actually i'm trying to prove a connept behind my project. I'm actually done with it.. but i'm not finalizing it.. so this phase comes with the evaluation phase too.. in order to do that, it has to be running a live.. since i dont have much time before the writing my thesis.. showing the logging will be easier way..

But i think even if it was shown.. i'm not sure too that the user will be able to write something, if a question was fired.

 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stefan,
Yes you are right.. but the thing is that mainly it is not necessarly to be a web application.. it could be a mobile application.. regardless to the interface and how the user is going to use the application, i was focusing more on the server side.. now since it is done.. i have selected web application since it can be run also on Mobile phones from the browser.. or later i can link it with an iphone application..

again you are right.. i could make multi-jsp pages.. but again.. in order to fire one.. i need it to go from a java class..
I would really appreciate it if there is any example to call a jsp from a java class it would be good!

I have tried something but it didnt work i dont know why

i will post it here, so guys maybe you can think with me.. how to get it work..


Thanks
Hend
 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the java code i have the following code:


this is the code of the bean:


now here is the code of the servlet


this is the jsp code


i'm certain something is wrong
please advise
 
Hend Ahmed
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so far i have edited the DynamicServlet to be like this


i get this error :

Exception in thread "thread" java.lang.NullPointerException
at Servlets.DynamicServlet.doGet(DynamicServlet.java:97)
at Servlets.DynamicServlet.run(DynamicServlet.java:71)
at java.lang.Thread.run(Unknown Source)
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmmm.
Where to start?

First of all your servlet should NOT implement runnable.
You should NOT start your own thread to invoke it.
You should NEVER create an instance of your servlet.

A Servlet is designed to be run in a container (like Tomcat)
You make an HTTP request to the container, and it will instanitate your Servlet class, and invoke the servlet's doGet method on your behalf.

I suggest you look through a basic tutorial on Tomcat and Servlets, get a handle on how they work, and then rethink your application design.

 
reply
    Bookmark Topic Watch Topic
  • New Topic