1 Replies - 605 Views - Last Post: 04 September 2011 - 08:25 PM

#1 AOM_Set  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 151
  • Joined: 18-December 10

Java (JSP)

Posted 27 August 2011 - 06:06 AM

Hi. I'm working on a little project of mine, and encountered an annoying problem.
I have some JSP code, and I need a variable that I have in a java class to be in that JSP. Look at the code, I have shown where the variable should be.
In the java class, the variable is declared like this:
String question = (String) getServletContext().getAttribute("question");


My question is... How do I get that variable to my JSP?

So I have written this code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QuickPollAsk</title>
</head>
<body>
	<h1>QuickPollQuestion</h1>	
	THIS IS WHERE THE QUESTION SHOULD BE-------------?
	<form method="POST" action="vote">
	<input name="vote" type="radio" value="yes"> Yes<br>
	<input name=vote type=radio value=no> No<p>
	<input type=submit name=submit value=Vote>
	</form>
</body>
</html>



Thanks

This post has been edited by AOM_Set: 27 August 2011 - 06:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Java (JSP)

#2 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: Java (JSP)

Posted 04 September 2011 - 08:25 PM

Hi there,

You can just use something like this at line 11;

<%= question %>


Hope this helps.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1