943,740 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 2522
  • JSP RSS
Jan 12th, 2009
0

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

Expand Post »
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.
  
JSP Syntax (Toggle Plain Text)
  1. public String getResult(String mw)
  2. {
  3. ...
  4. if(overallcount == 1.0)
  5. {
  6. String overallcount 4 = String.valueOf(overallcount1);
  7. return overallcount4;
  8. }
  9. else
  10. {
  11. String overallcount3 = String.valueOf(overallcount);
  12. for(int i=0; i<j; i++)
  13. {
  14. if(coeff[i] != 0.0)
  15. {
  16. finalcoeff[i] = ((coeff[i]/overallcount)*100);
  17. } // keep in mind that and array called element[], has already been filled
  18. }
  19. return overallcount3;
  20. }
  21. }

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darylesha is offline Offline
4 posts
since Apr 2006
Jan 12th, 2009
1

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

If you check this tutorial you should be able to find answer to your question
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: description The server encountered an internal error () that prevented it from fulfil
Next Thread in JSP Forum Timeline: Handling checkbox selection





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC