RSS Forums RSS

Accessing a array through a servlet and outputting info in a JSP?

Please support our JSP advertiser: Programming Forums
Thread Solved
Reply
Posts: 4
Reputation: darylesha is an unknown quantity at this point 
Solved Threads: 0
darylesha darylesha is offline Offline
Newbie Poster

Accessing a array through a servlet and outputting info in a JSP?

  #1  
Jan 12th, 2009
I have researched and have not come up with any examples and no answer as to how to do this. Please help... The molecular2.java does all the computation. I will only include a snippet of it.
This file is like this because I needed to return multiple items and could not find another way to do it.
 
public String getResult(String mw)
{
...
if(overallcount == 1.0)
{
String overallcount 4 = String.valueOf(overallcount1);
return overallcount4;
}
else
{
String overallcount3 = String.valueOf(overallcount);
for(int i=0; i<j; i++)
{
if(coeff[i] != 0.0)
{
 finalcoeff[i] = ((coeff[i]/overallcount)*100);
} // keep in mind that and array called element[], has already been filled
}
return overallcount3;
}
}

I want to pass the information hat I get here to a servlet that looks like this and is called MoleCalc.java

public class Molecalc extends javax.servlet.http.HTTPServlet implements javax.servlet.Servlet {
...
protected void doGet (...)
{
RequestDispatcher disp = request.getRequestDispatcher("jsp/Calculators/MoleCalc.jsp");
if((request.getParameter("submit")==null) || (request.getParameter("submit").length() == 0))
{//do nothing
}
else //user hits submit button
{
if((request.getParameter("mole") != null) && (request.getParameter("mole").length() > 0))
{
String moleS = request.getParameter("mole");
String moleStr = "";
String overallcount = "";
try
{
overallcount = Molecular2.getResult(moleS);
if(overallcount == "1.0")
{
request.setAttribute("mole","");
request.setAttribute("moleformula","");
request.setAttribute("errormsg", "Did no t enter a proper equation");
}
}
}
Could someone please tell me how to implement the array into this code? I have tried everything that I can imagine but it is not working.
I am figuring that for the jsp, which is MoleCalc.jsp, that I would just do a couple of foreach statements.
<form name = "moleformula" method="get" action="MoleCalc.java" onsubmit = "return vInputMoleformula(this);">
<h3>enter the Molecular Formula: </h3>
<td><input type="text" name="mole" id="mole" value="" maxlength="10" size="10"/> Molecular Formula </td>
<input class="submitButton" type="submit" value="Compute" name="submit" /> <br />
<h2> Molecular Weight = <c:out value="${moleformula}"/> g.</h2><br/>
<br> The formula entered was: <c:out value="${mole}"/><br/>
<h2><font color=red><c:out value="${errormsg}"/></font></h2><br/></form></div>

I am not a student working on an assignment for school and trying to weasle answers out of you all. I am terribly lost and am in desperate need of some suggestions as to how to attack this problem. Any help would be great.... Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Posts: 3,460
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Accessing a array through a servlet and outputting info in a JSP?

  #2  
Jan 12th, 2009
If you check this tutorial you should be able to find answer to your question
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 949 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:52 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC