Two Laptop Bag*
The moose likes JSP and the fly likes JSP colliding with HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSP colliding with HTML" Watch "JSP colliding with HTML" New topic
Author

JSP colliding with HTML

Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
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
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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.


Swastik
Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
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

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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.
Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
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 .
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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?

Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
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
Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
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
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

try it once again

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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.
Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
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
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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.
Padmaksha Mukhopadhyay
Greenhorn

Joined: Nov 27, 2012
Posts: 27
Is there any method to implement your thought.
Like can you send me some sample code .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP colliding with HTML