Reputation: 1316
I have the addedit.jsp page
where I am inserting myinput in a textarea
your input
<input id="thistextfield" type="text" name="ruleField" size="20" >
<input type = "submit" name = "submit" value = "submit">
<a href="SaveName.jsp">to savename</a>
my session gets stored in this page
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.lang.String" %>
<%
String ruleField = request.getParameter( "ruleField" );
session.setAttribute( "theName", ruleField );
%>
<html>
<head>
<title></title>
</head>
<body>
<a href="test2.jsp">Continue</a>
</body>
</html>
Here is my text2 page. where I am supposed to get back the session
Hello,<textarea > <%= session.getAttribute("theName")%> </textarea>
but the problem is that I get a null value in my textarea. And I am using IntelliJIdea 12 and the getParameter and getAttribute show up in red as cannot resolve method.
Upvotes: 0
Views: 1986
Reputation: 1662
You have missed out the HTML form tags in addedit.jsp. Therefore when you click on the link 'to savename' you are not sending the form data 'ruleField' as a parameter in the request, you are not sending any data, that is why it is null.
Make the following changes to the addedit.jsp:
<form method="GET" action="SaveName.jsp">
<input id="thistextfield" type="text" name="ruleField" size="20" >
<input type = "submit" name = "submit" value = "submit">
</form>
and remove the following HTML (this is superfluous):
<a href="SaveName.jsp">to savename</a>
I had thought that you might want to use a link to submit the form rather than a button. Here is alternative code that uses the link to submit the form.
<form method="GET" action="SaveName.jsp" id="form1">
<input id="thistextfield" type="text" name="ruleField" size="20" >
</form>
<div onclick="document.getElementById('form1').submit()">to savename</div>
Upvotes: 1