• Post Reply Bookmark Topic Watch Topic
  • New Topic

scriptlets problem  RSS feed

 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to enter create a html page in a jsp inside a while loop but its not working as the whole html content is getting printed in the browser instead of the values


 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36453
459
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at why you should avoid having Java code in your JSP.

Going on to your question, this page prints out something like this:
1564941393681<html><h1>tttttttttttttttttttttt</h1></html>

That's not a valid web page. A web page should have a body containing the content. And it shouldn't have random characters (from your loop) before the open html tag.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i use a table inside the loop to dynamically add rows....?if so please tell me how because i was atcually doing that but even for that it was not working...


i want to add rows dynamically with the values inside the while loop....can you please give me an example
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36453
459
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem isn't that values are output in the loop. The problem is that they happen before the <html> tag and there is no <body> tag. Forget about JSP for a minute. Try the following steps:

1) On your computer, create a html file that contains a bare bones web page that displays tttttttttttttttttttttt
2) Copy that HTML into your JSP unchanged (back it up first) and confirm it still displays tttttttttttttttttttttt
3) Add a loop inside the body.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ill try
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because that was creating invalid HTML.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I will strongly reiterate Jeanne's point: Java code in a JSP is a bad and obsolete practice from over 12 years ago. Java scriptlets should never be used in modern JSP pages.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have written the below code as you have told and it worked...



the output came as follows:


tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

tttttttttttt

0
1
2
3
4
5
6
7
8
9
10


but again i tried it in a different approach,like inserting values from a hashtable ...like the code mentioned below....



but i am not getting the desired output...the browser is showing the output as given below...


output:

<html>


<body>


<table>



enterd jsp
inside the try
entered after if in jsp
one



<tr>


<td>one</td>


</tr>



enterd after td in while




</table>

</body>

</html>

i am not understanding why its happening this way...please explain...



 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That output (the second one, not the first) looks perfectly reasonable to me. What do you think is wrong with it?
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the html tags are getting displayed along with the <td> value...why is that?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
puja dayal wrote:the html tags are getting displayed along with the <td> value...why is that?


I don't understand what that means. Yes, your code outputs <html> tags and it outputs a value inside a <td> element, which I thought was what you wanted. Perhaps you could explain what you expected, what you got instead, and how the two things are different?
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see the value but what about the tags being displayed.....i am sure the user wont like it if he sees the html tags being displayed.....i am sure even programmers wont like that either...am i wrong?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That usually means that the content type is set incorrectly, but I don;t see anywhere you are setting that. is that all of the code? How are you getting to the JSP?

And why are you still putting Java code in a JSP?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't understand. You wrote code to produce HTML and it produced HTML. Who is this user who is seeing tags displayed, and what does that mean?
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sorry but are you joking or are you trying to test me??? i mentioned the way i got the output.....when you write html what would you like to display to the browser? the output ONLY (OR) the html tags on the browser?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
puja dayal wrote:i am sorry but are you joking or are you trying to test me??? i mentioned the way i got the output.....when you write html what would you like to display to the browser? the output ONLY (OR) the html tags on the browser?

I strongly suggest that you take on a better tone when addressing people who are volunteering their time to help you.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trust me i was not being rude...i seriously felt he was joking..
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mr paul may be i was not clear in my explanation about my problem in the program.I am sorry for that and please forgive me....I would like to explain to you again...

i created a jsp page as follows...:





and i got the following output:

<html>


<body>


<table>



enterd jsp
inside the try
entered after if in jsp
one



<tr>


<td>one</td>


</tr>



enterd after td in while




</table>

</body>

</html>


i am happy to see the value being displayed in the <td> tag...but i desire the following output:


one


i dont want the <html> tags to be displayed on the browser...i hope i am clear now








 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36453
459
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul wasn't being rude. He was trying to see if there was a language barrier affected either parties' understanding. (There wasn't.) Also, please don't bump posts. It's only be three hours. In the middle of the night (US time). On the weekend. Due to timezones, it can take 24 hours for someone to get back to you. You just need to wait patiently. People aren't ignoring you.

Now back to your question. This code isn't valid HTML. Tables can't have random things in them - only <tr> tags and nested content in the <tr> tags. I'm thinking that since you don't since you don't specify a content type - as Bear noted - the browser guesses. When it sees valid HTML, it guesses right. When it sees invalid HTML, it no longer does.


By contrast, if you look at the source code for this page, you see that we specify it is an HTML page.

>
 
Niju Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello pooja in your page i can see some tags that need are missing.

before your <table> tag and after your <html> tag include <head> and <meta> tag as said by Jeanne.

Still if it is not, just refresh your browser (ctrl+f5). Please try and tell the result :).
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not working....i am still getting the output in the following way....:-(


output:


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

</head>

<body>

<table>




<tr>


<td>one</td>

<h1>tttttttttttt</ht>


</tr>



</table>

</body>

</html>

 
Niju Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After refreshing browser page (ctrl+F5) you getting the same result? Also please copy url and try some other browser.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...i tried in chrome,firefox,ie......i am getting the same output in all the browsers.....i also used refresh as you said....but still its not coming
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the html is invalid then what corrections should i do to make it valid...please let me know..i have been struggling with this problem since 2 days. :banghead:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's easy to find information on HTML validation, and even online validators. But Jeanne has already given you the answer: you can't just stick any element into a table.

In any case, I don't think the HTML is your problem. Perhaps you should answer the questions I've already posed?
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i thought there is a way in creating dynamic tables with values.?...and what questions should i answer.?..i didnt get you
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i want to know how to add rows dynamically
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Earlier I asked:
Bear Bibeault wrote:Is that all of the code? How are you getting to the JSP?

And why are you still putting Java code in a JSP?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I would recommend at this point is to create a simple JSP in the root folder of the application with just:

If it does not display just 7 in the browser, your configuration or web structure is wonky.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried the above code which you gave me....i am getting the following output..


output:


${3+4}


so now what is the problem and how should i resolve it???

 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What server are you using and what version of it? How do you deploy your application? What URL do you access to get to that JSP?
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not using any IDE currently....i am manually deploying the project and running....i am using tomcat server (6.0)..i deployed my project in webapps folder in the server...my project folder name is proj and inside this folder and outside WEB-INF folder i placed the .jsp file...in which i am getting this problem


url: http://localhost:8080/proj/example.jsp
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the web.xml
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's my web.xml





 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The web-app element is missing something: https://www.coderanch.com/how-to/java/ServletsWebXml

Also, you should always put all classes into packages. You will run into problems otherwise.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no..i dont think that is the problem..the problem is something else...i am not understanding where...may be its my luck..
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
puja dayal wrote:no..i dont think that is the problem..

There may be many problems, but this is one of the problems. I'd not ignore this advice.
 
puja dayal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ...ill try this also....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without a correct deployment descriptor, the web app will not be propoerly configured.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!