?
Solved

Build web page dynamically

Posted on 2006-06-13
5
Medium Priority
?
246 Views
Last Modified: 2010-04-06
Hi,

In a web based application using jsp/htmls at front end, I need to build a page dynamically. Mean, I have to first ask few questions to the user and based on their answers only, I have to build and display the page accordingly.

Please help me know how can I do this in a web based application using java-j2ee technology.

Thanks,
Vinay.
email:vinay_aggarwal76@yahoo.com
0
Comment
Question by:Vinay_enjoy
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Eternal_Student
ID: 16892835
I would use a form with lists to display possible choices and depending on the users choices display a different style sheet.

That would be a simple option .. alternatively you could pass the values into the css styles inline. So you store the value in a variable, post that variable to the page that generates the layout/style etc etc and then extract the variable where needed.

Not sure entirely what you wish to achieve but that is a basic over-view.
0
 
LVL 2

Expert Comment

by:Mr_Lenehan
ID: 16903918
I would agree mostly with Eternal_Student, I'd do something like:

<%
String param1 = ""+request.getParameter("param1");
if(param1 .equals("null")){
//give a form to fill in
%>
<form action="thispage.jsp" method="post">
<input type="text" name="param1">
</form>
<%
}
else{
//do somthing with the values
if(param1.equals("0")){
%>
<!-- do stuff that would happen if param1 was 0 -->
<% } //endif%>

<% }//endelse %>
0
 

Author Comment

by:Vinay_enjoy
ID: 16917552
Thanks Guys. Let me elaboarte my requirement.
1. I have to display a table on the web page. But I have to ask the user first how many rows and columns he want. Based on his answer only, I would display thta many rows & cols.

2. Then I would ask the user what features he want. This will determine the name of the cols. Whatever features he chose from many check box options, those features will become the col heading.

3. In the final table, the left most col for Serial No will appear by default and it will be non-editable. The values will be 1 to n, populated automatically when the page/table gets displayed,  depending on how many rows the user has chosen.

Appreciate further inputs on this.

Thanks Again,
Regards,
Vinay.
email:vinay_aggarwal76@yahoo.com


0
 
LVL 2

Accepted Solution

by:
Mr_Lenehan earned 500 total points
ID: 16919813
So something like:

<%
String rows= ""+request.getParameter("rows");
String cols= ""+request.getParameter("cols");
String rowTitle1 = ""+request.getParameter("rowTitle1");
String rowTitle2 = ""+request.getParameter("rowTitle2");
String rowTitle3 = ""+request.getParameter("rowTitle3");
String colTitle1 = ""+request.getParameter("colTitle1");
String colTitle2 = ""+request.getParameter("colTitle2");
String colTitle3 = ""+request.getParameter("colTitle3");
//keep adding title vars depending on the max dimensions of the table
if(rows .equals("null")){
//give a col/row selection form to fill in
%>
<form action="thispage.jsp" method="post">
<select name="cols">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>
<select name="rows">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>
<input type="submit">
</form>
<%
}
else if(rowTitle1.equals("null")){
//give a col/row heading form to fill in
%>
<form action="thispage.jsp" method="post">
<input type="hidden" name="rows" value="<%=rows%>">
<input type="hidden" name="cols" value="<%=cols%>">
<%
for(int i =1;i<=Integer.parseInt(rows);i++){
%>
      rowTitle<%=i%>:<input type="text" name="rowTitle<%=i%>"><br>
<%
}
for(int i =1;i<=Integer.parseInt(cols);i++){
%>
      colTitle<%=i%>:<input type="text" name="colTitle<%=i%>"><br>
<%
}%>
<input type="submit">
</form>
<%
}
else{
//assume both forms filled and do something

//build some title arrays... add to these depending on max col/row vals
String[] rowTitles = {rowTitle1,rowTitle2,rowTitle3};
String[] colTitles = {colTitle1,colTitle2,colTitle3};

String table = "<table><tr><td><!--blank top left cell--></td>";
//build and add col titles
int numCols = Integer.parseInt(cols);
for(int i = 0;i<numCols ;i++){
      table+="<td>"+colTitles[i]+"</td>\n";
}
table+="</tr>";
int numRows = Integer.parseInt(rows);
for(int n =0;n<numRows;n++){
      String aRow = "";
      aRow+="<tr><td>"+rowTitles[n]+"</td>";
      for(int i = 0;i<=numCols ;i++){
            aRow+="<td></td>\n";
      }
      aRow+="</tr>\n";      
      table+=aRow;
}
table+="</table>";
%>
<%=table%><%

}//endelse %>


Basically this checks if they've selected number of rows, if they've not it gives them a form to specify rows and cols. If they have specified rows and cols it gives them a form to fill in titles. If they've specified titles then in nocks out a table with the row and col headings.

To expand it you need to add more variables to cope with more or less cols being specified... and then update the String arrays in the final else to include the extra titles.

Hope this gives you a kick start.
0
 

Author Comment

by:Vinay_enjoy
ID: 16931782
Thanks a lot Lenehan !!!

 This is very useful piece of code.

Cheers,
Vinay.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question