Solved

Build web page dynamically

Posted on 2006-06-13
5
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 125 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

726 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