Forums Register Login

JSP colliding with HTML

+Pie Number of slices to send: Send
Someone Please help

Here is my code

<%@ page import ="java.util.*"%>
<%@ page import ="java.io.*"%>

<html>
<head>
<title>Radio Button</title>

</head>

<body>
<div style="width:90%;height:200%;border:10px solid green;">

<% BufferedReader br= new BufferedReader(new FileReader("C:/tomcat/webapps/myJSP/temp.txt"));
String line=null;
String wrd=null;
while((line=br.readLine())!=null)
{
Scanner sc = new Scanner(line);%>
<% { %>
<form name="frm" action="CheckSplit.jsp" method="post" >

<% if(sc.hasNext("Question1"))
{
out.println(line);
} %>
<% if(sc.hasNext("1.1"))
{
String word[]=line.split(":");
wrd= word[1];
%>
<input name="radioButton" type="radio" value="1" checked="checked"/> <% out.println(wrd);%>
<%} %>
<% if(sc.hasNext("1.2"))
{
String word[]=line.split(":");
wrd= word[1];%>
<input name="radioButton" type="radio" value="2" /><% out.println(wrd);%>
<%}
if(sc.hasNext("1.3"))
{
String word[]=line.split(":");
wrd= word[1];
%>
<input name="radioButton" type="radio" value="3" /><%out.println(wrd);%>
<%}
if(sc.hasNext("1.4"))
{
String word[]=line.split(":");
wrd= word[1];%>
<input name="radioButton" type="radio" value="4" /><% out.println(wrd);%>
<%} %>



<div style="width:100%;border-top:1px dashed #000000;line-height:0px;"></div>



<%

if(sc.hasNext("Question2"))
{
out.println(line) ;}%><br>
<%
if(sc.hasNext("2.1"))
{
String word[]=line.split(":");
wrd= word[1];%>
<input name="radioButton1" type="radio" value="1" checked="checked"/> <%out.println(wrd);%>
<%}
if(sc.hasNext("2.2"))
{
String word[]=line.split(":");
wrd= word[1];%>
<input name="radioButton1" type="radio" value="2" /> <%out.println(wrd);%>
<% }
if(sc.hasNext("2.3"))
{
String word[]=line.split(":");
wrd= word[1];%>
<input name="radioButton1" type="radio" value="3" /><%out.println(wrd);%>
<% }
if(sc.hasNext("2.4"))
{
String word[]=line.split(":");
wrd= word[1];%>
<input name="radioButton1" type="radio" value="4" /> <%out.println(wrd);%>
<% } %>
<% } %>
<% } %>
<input name="goto" type="submit" value="Submit" />
</form>
</div>
</body>
</html>


I am trying to put a single horizontal line between my 2 questions but it is putting the hr line multiple ones why? can anybody please help.I have an project to fininsh? Is this colliding with the jsp while loop. If someone can answer this i will be very greatful
+Pie Number of slices to send: Send
First of all put your code in code tags, it becomes easier to read. Second point it's not a good practice to embed code java code inside jsp, it should be done in servlet. Jsp is a view and it should just display the processed output.
+Pie Number of slices to send: Send
I have put all the codes in tags . Can you please tell me how to make the hr tag print only once. If possible can you please show me . Here is my text file from where i am reading

Question1 : Which is used to print in a new line in Java

1.1 :System.print
1.2 :System.out.println
1.3 :Out.print
1.4 :Out.println

Answer1 :2


Question2 : Which statement has case values associated to it

2.1 : If
2.2 : For
2.3 : Switch
2.4 : While

Answer2 :3

+Pie Number of slices to send: Send
You probably didn't get my point. On the top you will find a code button. Click that button and paste your code within those tags, it will become easier to read. Now coming to your question, I couldn't find any hr tag in the code.
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Thank you the issue is whatever i use be it div or hr tag to draw a simple line between the 2 questions the line comes up multiple times dividing my page into many parts .Is it because of the while loop , because java and html are not to collide in jsp. Even when i am putting br tags it is putting wider gaps than it should .
+Pie Number of slices to send: Send
This should show you some difference, but your data file design does not look too good. How many times will you keep doing if .. else if. Now you have two questions, what happens when you have 100 questions?

+Pie Number of slices to send: Send
Hey Swastik thanks a lot . I am going to test it now . Thats even my question What if there were 100 questions. Infact there are 10 for me to do. The requirement was that .... You have to read from a file the questions and answers and if required they will change the questions from the text file it should reflect in the output too . I saw no other way but to put tags in the text file use scanner to read the file inside the radio buttons itself . Let me know if there is a better way. I am pretty new to jsp. And i find itb easier than servlets. Thats why i am using this code. I am pretty good in java. But servlets is a problem thats why.Again if the code works Thanks thanks a lot . I will let you know what happens
+Pie Number of slices to send: Send
Hi Swastik its not working . I want this div to divide the questions ie

Question1 : Which is used to print in a new line in Java

System.print
System.out.println
Out.print
Out.println


in here the line should come -----------------------------------------------------------------

Question2 : Which statement has case values associated to it


If
For
Switch
While



But when i put the tag there it is printing multiple times why ?? If you are there please let me know
+Pie Number of slices to send: Send
try it once again

+Pie Number of slices to send: Send
Due to your data design its getting more complex. Data base is always a better option for this. However even if you use text files you can think of the following design

Question file (1st column is the question number second column is the question)
-------------------
1-What is the capital of India
2-What is the capital of Nepal

Answer file (questionnumber-ans1-ans2-ans3-ans4-correctansnum)
-------------
1-Delhi-Kolkata-Mumbai-Chennai-1
2-Islamabad-Dhaka-Beijing-Kathmandu-4

The above is my thought, there can always better options.
+Pie Number of slices to send: Send
Hey thanks Swastik it works now . Now i am understanding how to control the br tags too. thanks a lot Again. If you find a better way to do the program please keep me posted . By the way i think you are from India and you are a fabulous programmer. If there is any way to do the program through servlets keep me posted or send the program . Thanks
+Pie Number of slices to send: Send
Yes I am from India. But the programming approach is not all good. This was just a quick fix for your problem. We should never have java codes inside jsp, its a very old practice. Jsp should be only done using tags, like jstl/el/custom tags etc.
+Pie Number of slices to send: Send
Is there any method to implement your thought.
Like can you send me some sample code .
+Pie Number of slices to send: Send
As Swastik Dey has already pointed out, putting Java code in a JSP is a poor practice that had been obsolete and discredited for over 10 years now. Please see this JspFaq entry.
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1152 times.
Similar Threads
JSP <a href> tags breaks page functionality
calendar
struts html tag question
request.setAttribute() and request.getAttribute()
calendar
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:43:51.