• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert servlet into jsp page ?  RSS feed

 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to convert servlet into jsp. but i dnt know how to convert servlet into jsp.
This is my Servlet

 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know how to write a JSP, it should be simple. You take all your out.println()'s, put the content in a JSP, put the data in your request and use EL to get the data inside your JSP.

If you don't know how to write a JSP, it's time you picked up a book.

And for the love of everything, use some good practices.
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you. actually i had tried this, but i am unable to do it.
please give me some suggessions.

 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the jsp code that you have done so far.
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying this so far..

 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not have any kind of java code in jsp, it's a very old practice. Jsp is just to represent the data i.e view. Do computations/calculations in servlet pass the computed result to jsp using scoped variables. Now in jsp use that scoped variable to present the output using EL.
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, i want to shows the different images on index page and after selecting a particular image it should show the black and white pixels from that image n the size of image but on the same page(ajax).
For this i used ajax and this servlet but from index page this servlet is not getting call in ajax. If we use jsp instead of servlet then is getting called from ajax in jsp. so I am trying to convert the given servlet to jsp.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your requirement is whatever is there in out.println in servlet should be printed using jsp?
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it is.
 
krishna atok
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anuja, You have to use proper url-mapping for the servlet to get called, for this please use relative url which is subjected to the context where you have deployed your web application.
Your servlet will get invoked only through url-mapping. Please try. also as suggested by Swastik you shouldnt use jsp for java code as it is limited to only view purposes.

Thanks,
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you kesava. but i used full URL like http://localhost:8080..... but still it's not working.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you mean by not working? Please be more specif are you getting any error/exception?
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my jsp page






from this page after clicking on search button i want to display servlet. but it's giving HTTP Status 404.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you done the url-mapping for servlet in web.xml?
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i had done URL-MAPPING in web.xml.


 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your url-pattern in web.xml does not match with this

rcvReq.open("GET", "JavaWalkBufferedImageTest1?", true);
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Means what? What I have to do for it ?
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
probably this.

 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is giving HTTP Status 405 - HTTP method GET is not supported by this URL.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your servlet you are implementing doPost method. But in your ajax call, method type is get.
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please solve this issue ? I am not getting what to do?
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


change the above to

 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thaks Swastik for your efforts. but now when i click on search button it's not giving any thing.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if you are getting any exception?


and bye the way where does that cid file exist?
 
Anuja Deshmukh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it's not giving any exception. and I have to use image that pass on jsp page on this servlet. on jsp page name of image tag is "cid", which i had used on servlet.

 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You approach is not correct. cid is nothing but the name of the img tag. But probably you need to process hair.jpg stored in images folder. So argument to File should be different.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File file=new File("cid")

should be



or



depending upon which one is requested for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!