Solved

Build web page dynamically

Posted on 2006-06-13
5
226 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 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now