Iam working on a project in JSP using netbeans.
Iam getting the following error......but i didn't find the java any files..please provide me something.The error is:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 205 in the generated java file
Syntax error, insert "Finally" to complete TryStatement
An error occurred at line: 206 in the generated java file
Syntax error, insert "}" to complete ClassBody
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
The files i used are:
addNewUser.jsp:
<%# page language="java" %>
<%# page session="true" %>
<%# page import="java.util.*" %>
<HTML>
<head>
<LINK href="styles.css" type="text/css" rel="stylesheet">
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
history.go(+1);
function validate(){
x = document.NewUser.uid;
y = document.NewUser.pwd;
z = document.NewUser.auth;
var ed=x.value;
var pd=y.value;
var ad=z.value;
var pattern = /^([a-zA-Z0-9\_\.]{4,10})$/;
var Apattern = /^([0-3]{1})$/;
if(!(pattern.test(ed))){
alert("Invalid username");
return false;
}
else if(!(pattern.test(pd))){
alert("Invalid password");
return false;
}
else if(!(Apattern.test(ad))){
alert("Invalid Authentication");
return false;
}
else
return true;
}
//-->
</SCRIPT>
<br><br>
<body Class=Grad>
<center>
<BR><BR><br><br>
<FONT FACE="Century Gothic">
<FONT size="2" color="blue" FACE="Century Gothic">
<FORM NAME="NewUser" ACTION="AddNewUser1.jsp" METHOD="POST" onsubmit="return validate()">
<TABLE Border=0 align=center>
<TR class=row_title ALIGN="center">
<TH COLSPAN="2"> Add user</TH>
</TR>
<TR class=row_even>
<TD>UserID * </TD>
<TD><input TYPE=text name=uid size="10" maxlength="10"></TD>
</TR>
<TR class=row_odd>
<TD>Password * </TD>
<TD><input TYPE=password name=pwd size="10" maxlength="20"></TD>
</TR>
<TD><input type=hidden name=auth value=2>
<TR class=row_even>
<TD><INPUT TYPE=submit name=submit value="Submit">
</TD>
<TD><INPUT TYPE=reset name=resett value="Reset" >
</TD>
</TR>
</TABLE>
<A align="center" href="Login.jsp">BACK TO HOME</A>
</FORM>
</BODY>
</HTML>
addNewUser1.jsp:
<%# page language="java" %>
<%# page session="true" %>
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<%# page import="java.util.Random" %>
<html>
<head>
<LINK href="styles.css" type="text/css" rel="stylesheet">
<SCRIPT LANGUAGE="JavaScript">
<!--
history.go(+1);
//-->
</SCRIPT>
</head>
<jsp:include page="MultiLevelmenu.htm"/><br><br><body Class=SC>
<center>
<BR><BR>
<FONT FACE="Century Gothic">
<!--Declaration of varaibles-->
<%! String errormsg ;%>
<%! String disluserid ;%>
<%! String dislpwd ;%>
<%! int auth ;%>
<%
/*Retreiving user id and password*/
disluserid = request.getParameter("uid");
if(disluserid == null)
disluserid = "";
dislpwd = request.getParameter("pwd");
if(dislpwd == null)
dislpwd = "";
String sauth = request.getParameter("auth");
if(sauth == null)
auth=0;
auth = Integer.parseInt(sauth);
//System.out.println(disluserid+dislnewpwd+dislpwd);
%>
<%
/*Declaration of variables*/
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
String Userid,Password;
try
{
/*Getting the connection variable from session*/
con=(Connection)session.getAttribute("connection");
stmt = con.createStatement();
String Query = "SELECT * from student where studentid = \'"+disluserid+"\'";
System.out.println(Query);
rs = stmt.executeQuery(Query);
}
catch(Exception e)
{
System.out.println("Exception"+e);
/* If user provides valid username & password then update the new password to database*/
if(rs.next())
{%>
<script>
for(i=1;i<=6;i++) document.write("<br>");
</script>
<H3 align="center"> User already exists</H3>
<BR>
<center>
Back
</center>
<%
}
else{
String UpdateQuery =
"Insert into student values(\'"+disluserid+"\',\'"+dislpwd+"\',"+auth+")";
//System.out.println(UpdateQuery);
int rowsAffected=stmt.executeUpdate(UpdateQuery);
//System.out.println("Rows Affected = " + rowsAffected);
if(rowsAffected==1)
{%>
<script>
for(i=1;i<=10;i++) document.write("<br>");
</script>
<H3 align="center">User Created Successfully </H3>
Create Another User
<br/>
Home
<BR>
<%}
/* If user provides invalid password or username*/
else{%>
<script>
for(i=1;i<=6;i++) document.write("<br>");
</script>
<H3 align="center">Unable to create user please try again </H3>
<BR>
<% } %>
<%
}
%>
</FONT>
</center>
</BODY>
</html>
try {
/*Getting the connection variable from session*/
con=(Connection)session.getAttribute("connection");
stmt = con.createStatement();
String Query = "SELECT * from student where studentid = \'"+disluserid+"\'";
System.out.println(Query);
rs = stmt.executeQuery(Query);
} catch(Exception e) { System.out.println("Exception"+e);
In the above code section you are not completing the try's catch block.
Related
I have three JSP as follows:
Employee_vendor_approve.jsp : which is retrieve Employee Details
update_employeeVendorLoginCredentials.jsp: Which is take reference of Employee_vendor_approve.jsp page for upadate process
update_process_employeeVendorLoginCredentials.jsp: is update retrieve data
from point 1 i can able to retrieve data but i unable to proceed point 2 and 3. where is problem i unable to find, when i click update link on Employee_vendor_approve.jsp, update_employeeVendorLoginCredentials.jsp showing blank here is my code
Employee_vendor_approve.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee and vendor approve Page</title>
</head>
<body>
<table border="1" align="center">
<tr>
<td>FIRST_NAME </td>
<td>LAST_NAME</td>
<td>ORGANIZATION_NAME</td>
<td>EMPLOYEE_ID</td>
<td>Approve</td>
<td>Status</td>
</tr>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con==DriverManager.getConnection("jdbc:oracle:thin:#173.18.114.213:1821:godb","ex","xe");
statement=con.createStatement();
String Sql="SELECT FIRST_NAME,LAST_NAME,ORGANISATION_NAME,EMPLOYEE_ID,APPROVE from REGISTRATION_EMPLOYEE where role in ('Employee','Vendor')";
resultSet=statement.executeQuery(Sql);
while(resultSet.next()){
%>
<tr>
<td><%=resultSet.getString("FIRST_NAME")%></td>
<td><%=resultSet.getString("LAST_NAME")%></td>
<td><%=resultSet.getString("ORGANISATION_NAME")%></td>
<td><%=resultSet.getString("EMPLOYEE_ID")%></td>
<td><%=resultSet.getString("APPROVE")%></td>
<td>
update
</td>
</tr>
<%
}
//con.close();
%>
</table>
</body>
</html>
update_employeeVendorLoginCredentials.jsp:
<html>
<body>
<form method="post" action="update_process_employeeVendorLoginCredentials.jsp">
<table border="1">
<tr>
<th>FIRST_NAME </th>
<th>LAST_NAME</th>
<th>ORGANIZATION_NAME</th>
<th>EMPLOYEE_ID</th>
<th>Approve</th>
</tr>
<%
String employee_id=request.getParameter("employee_id");
int sumcount=0;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#173.18.114.213:1821:godb","ex","xe");
Statement st=con.createStatement();
String query="SELECT FIRST_NAME,LAST_NAME,ORGANISATION_NAME,EMPLOYEE_ID,APPROVE from REGISTRATION_EMPLOYEE where EMPLOYEE_ID="+employee_id;
ResultSet rs=st.executeQuery(query);
while(rs.next())
{
%>
<tr>
<td><input type="text" name="FIRST_NAME" value="<%=rs.getString("FIRST_NAME")%>"> </td>
<td><input type="text" name="LAST_NAME" value="<%=rs.getString("LAST_NAME")%>"> </td>
<td><input type="text" name="ORGANISATION_NAME" value="<%=rs.getString("ORGANISATION_NAME")%>"> </td>
<td><input type="text" name="APPROVE" value="<%=rs.getString("APPROVE")%>"> </td>
<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<% }
}
catch(Exception ex)
{
}
%>
</table>
</form>
</body>
</html>
update_process_employeeVendorLoginCredentials.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#173.18.114.213:1821:godb","ex","xe");
String EMPLOYEE_ID=request.getParameter("EMPLOYEE_ID");
String first_name=request.getParameter("FIRST_NAME");
String Last_name=request.getParameter("LAST_NAME");
String ORGANISATION_NAME=request.getParameter("ORGANISATION_NAME");
String Approve_status=request.getParameter("APPROVE");
if (EMPLOYEE_ID!=null)
{
// Connection con = null;
PreparedStatement ps = null;
int personID = Integer.parseInt(EMPLOYEE_ID);
try
{
String Sql="update REGISTRATION_EMPLOYEE set APPROVE='Y' where EMPLOYEE_ID="+EMPLOYEE_ID;
ps=con.prepareStatement(Sql);
ps.setString(1, Approve_status);
int i=ps.executeUpdate();
if(i>0)
{
out.print("Record Updated Successfully");
}
else
{
out.print("There is a problem in updating Record.");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
%>
</body>
</html>
In Employee_vendor_approve.jsp: you set parameter name called id
update
but in update_employeeVendorLoginCredentials.jsp you get the parameter via employee_id
String employee_id=request.getParameter("employee_id");
They do not keep the same,so you get empty value.In order to solve this,you can change it to below:
String employee_id=request.getParameter("id");//using id instead of employee_id
To the problem you can not update data,it's also due to you fetch wrong value in update_employeeVendorLoginCredentials.jsp:
<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString(1)%>"></td> // you have get the wrong value for id
In order to let it work,change it as below:
<td><input type="hidden" name="EMPLOYEE_ID" value="<%=rs.getString("EMPLOYEE_ID")%>"></td>
I'm a beginner programmer, I already build page for data entry and page show all entries, but now I want to show specific row inside the table, which code can help me?
My table columns: fullname - email - Phone - education
I want to search by email to show the other data in one page.
I found this code on internet:
<%#page import="java.sql.*"%>
<% Class.forName("com.mysql.jdbc.Driver");%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
public class Showit {
String URL = "jdbc:mysql://localhost/regdata";
String USERNAME = "root";
String PASSWORD = "admin";
Connection conn = null;
PreparedStatement selectRegister = null;
ResultSet resultSet = null;
public Showit() {
try {
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
selectRegister = conn.prepareStatement(
"SELECT a.fullname, a.email,"
+ " FROM mainr a,"
+ "WHERE a.fullname = ?"
+ "AND a.email = ?");
} catch (Exception e) {
e.printStackTrace();
}
}
public ResultSet getShowit(String fullname, String email) {
try {
selectRegister.setString(1, fullname);
selectRegister.setString(2, email);
resultSet = selectRegister.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
return resultSet;
}
}
%>
<%
String fullname = new String();
String email = new String();
if (request.getParameter("fullname") != null) {
fullname = request.getParameter("fullname");
}
if (request.getParameter("email") != null) {
fullname = request.getParameter("email");
}
Showit showit = new Showit();
ResultSet showits = showit.getShowit(fullname, email);
%>
<table border="1">
<tbody>
<tr>
<td>Full Name</td>
<td>Email</td>
<td>Title</td>
</tr>
<% while (showits.next()) {%>
<tr>
<td><%= showits.getString("fullname")%></td>
<td><%= showits.getString("email")%></td>
<td><%= showits.getString("Phone")%></td>
</tr>
<% }%>
</tbody>
</table>
</body>
</html>
which connect with this page:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.sql.*"%>
<%#page import="java.util.Scanner" %>
<% Class.forName("com.mysql.jdbc.Driver");%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search</title>
</head>
<body>
<form name="search" action="display.jsp" method="POST">
<table border="0">
<tbody>
<tr>
<td>Full Name</td>
<td><input type="text" name="fullname" value="" size="50" /></td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="text" name="email" value="" size="50" /></td>
</tr>
</tbody>
</table>
<input type="reset" value="Reset" name="reset" />
<input type="submit" value="Submit" name="Submit" />
</form>
</body>
</html>
but it's not work.
The issue may be with this line:
fullname = request.getParameter("email");
Note that you are assigning the email parameter to the fullname variable.
first what i see is that the Query is wrong. Remove the , after the table alias "a" (here line 2) like this:
"SELECT a.fullname, a.email,"
+ " FROM mainr a"
+ "WHERE a.fullname = ?"
+ "AND a.email = ?");
There is also an issue here:
<td><%= showits.getString("Phone")%></td>
You did not include Phone in the SELECT statement, so it will not exist in the ResultSet.
I wish to create a simple script to store information dynamically without refreshing or redirecting to another page. I've sourced high and low for answers before coming here, and I followed this.
However, I'm still unable to get it to store data because I don't know where I've goen wrong. Also, I wish to ask the purpose of success: function(msg)
Thanks a lot!
Update 1: Got it to work after following Anoop's solutions. However, such a popup appears when the data is submitted
StaffReg.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Staff Registration</title>
</head>
<body>
<%-- HTTP header --%>
<%response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache");
response.addHeader("Expires","0");
%>
<%-- Javascript --%>
<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#Register').click(function(e) {
e.preventDefault();
$.ajax({
url: "StaffRegAuth.jsp",
type: "post",
data: {
username: $('#username').val(),
password: $('#password').val(),
userGroup: $('#userGroup').val()
},
success: function(msg) {
alert(msg);
}
});
});
});
</script>
<%-- Main body --%>
<h1 align="center"> Account Registration: </h1>
<div align="center">
<table style="width = 30%" >
<tr>
<td> User Name: </td>
<td><input type="text" id="username"></td>
</tr>
<tr>
<td> Password: </td>
<td><input type="password" id="password"></td>
</tr>
<tr>
<tr>
<td> User Group: </td>
<td><select name = "userGroup" id="userGroup">
<option value="1">Administrator
</optin>
<option value="2">Clerk
</optin>
<option value="3">Operations
</optin>
<option value="4">Sales
</optin>
</select></td>
</tr>
<tr>
</table>
<input type="submit" value="Register" id="Register">
</div>
</body>
</html>
StaffRegAuth.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<%-- Imports --%>
<%# page import="java.sql.*"%>
<%# page import="java.util.*"%>
<%#page import="javax.servlet.*" %>
<%#page import="javax.servlet.http.*" %>
<%-- HTTP header --%>
<%response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache");
response.addHeader("Expires","0");
%>
<%-- Variables that will be written --%>
<% String sUsername = request.getParameter("username");
String sPassword = request.getParameter("password");
int sUserGroup = Integer.parseInt(request.getParameter("userGroup"));
%>
<%-- Creating new staff account - writing --%>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String conURL= "jdbc:odbc:HOD_DATA";
Connection con = DriverManager.getConnection(conURL);
Statement st = con.createStatement();
int status = st.executeUpdate("insert into Staff(username, password, user_group) values('"+sUsername+"','"+sPassword+"',"+sUserGroup+")");
if(status>0){
//out.println("Update sucessful");
}
else{
//out.println("Update unsuccessful");
}
st.close();
con.close();
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>
Remove the submit button and use a normal html button with Id as Register.
Modify your html input types and replace the name attribute with id attribute. Ex: use id="username" instead of name="username"
Debugging:
Use firebug to check what value is passed to server. Ensure the correct ajax request is submitted.
Hope it helps.
i have project,in this i just save the two values into mysql database,it working fine.my requirement is i want to send the data by using postman,but those values are not saved into database and i din't get any exception,please help me how to solve this problem.
mycode is:
homepage.jsp
<%# 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>Insert title here</title>
<script type="text/javascript">
function validateForm()
{
var x=document.getElementById("location").value;
if( x == "" )
{
alert( "Please Enter The Location!" );
return false;
}
var y=document.getElementById("time").value;
if( y == "" )
{
alert( "Please Enter The Time!" );
return false;
}
var digits = "0123456789";
var temp;
for (var i = 0; i < document.getElementById("time").value.length; i++) {
temp = document.getElementById("time").value.substring(i, i + 1);
if (digits.indexOf(temp) == -1) {
alert("Please enter correct time");
document.getElementById("time").focus();
return false;
}
}
}
</script>
</head>
<body bgcolor="cyan">
<form name="myForm" method="post" action="insert.jsp" onsubmit="return validateForm()">
<div style="background-image:url(bg.jpg);">
<center><h1><font color="red">TRAFFIC INFORMATION SYSTEM</font></h1></center><br>
</div>
<hr size="10" color="red">
<center>
<table cellpadding="12">
<tr>
<td align="left">
Location</td><td> <input type="text" name="location"></td>
<tr>
<td align="right">
Expected Time
</td>
<td align="left">
<input type="text" size="3" name="time" maxlength="3">
Minutes
</td>
</tr>
<tr><td></td>
<td><input type="image" src="submit.gif" alt="Submit" width="48" height="48"/></td></tr>
</table>
</center>
</form>
</body>
</html>
insert.jsp
<%
DBCreation creation;
Connection connection;
String location;
String time;
location=request.getParameter("location");
time=request.getParameter("time");
connection=new DBCreation().getConnection();
try {
PreparedStatement statement=connection.prepareStatement("insert into Jam_Info values(?,?)");
statement.setString(1, location);
statement.setString(2, time);
int i=statement.executeUpdate();
if(i>0)
{
RequestDispatcher dispatcher=request.getRequestDispatcher("success.jsp");
dispatcher.forward(request, response);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>
You will have to write commit, to save data
connection.commit();
You have not close the connection.
connection.close();
write that it in the Finally block.
Right now I'm creating email client using javamail API, in which when I click on Reply button then the address of From field is not coming in To field.
DisplayMessage.jsp
<%# page import="user.*" %>
<%# page import="javax.mail.*" %>
<%# page import="javax.mail.internet.*" %>
<%# page import="javax.activation.*" %>
<%# page import="java.io.*" %>
<%
String sendmessage=(String)request.getAttribute("sendmessage");
if(sendmessage==null)
{
sendmessage="";
}
if (session == null) {
response.sendError(404, "Session expired");
return;
}
userinfo info = (userinfo)session.getAttribute("userinfo");
Session sessio = info.getSession();
Store store = sessio.getStore("imap");
store.connect(info.getHostname(),info.getusername(),info.getpassword());
Folder folder = store.getFolder(info.getUrl());
folder.open(Folder.READ_WRITE);
Message[] message = folder.getMessages();
int count = folder.getMessageCount();
int unread = folder.getUnreadMessageCount();
Integer messageno=Integer.parseInt(request.getParameter("messageno"));
%>
<html><head><title>Home Page</title></head>
<body>
<table width="940" bgcolor="#GSDFES">
<tr><td><input type="submit" name="button" class="button" onclick="javascript:deletemail(<%=messageno%>)" value="Delete"/></td>
<tr><td>From : <%= message[messageno].getFrom()[0] %></td></tr>
<tr><td>Subject : <%= message[messageno].getSubject() %></td></tr>
<tr><td>Date : <%= message[messageno].getSentDate() %></td></tr>
<tr><td>ContentType : <%= message[messageno].getContentType() %></td></tr>
<tr><td>
<%
InputStream stream = message[messageno].getInputStream();
while (stream.available() != 0) {
%>
<%
char str=((char)stream.read());
if(str=='\n')
{ %><br/><% continue;} %>
<% if(str==' ')
{ %> <% } %>
<%= str %>
<%
}
%>
</table>
<button class="button" name="reply" onClick="javascript:loadreplymessage(<%=messageno%>)">Reply</button><button class="button" onClick="javascript:loadforwardmessage(<%=messageno%>)" name="forward">Forward</button>
</body>
</html>
Function is written in different file home.jsp:
function loadcomposemail()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("tableview").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","composemail.jsp",true);
xmlhttp.send();
}
function loadreplymessage(i)
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("tableview").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","composereplymail.jsp?messageno="+i,true);
xmlhttp.send();
}
composereplymail.jsp:
<%# page import="user.*" %>
<%# page import="javax.mail.*" %>
<%# page import="javax.mail.internet.*" %>
<%# page import="javax.activation.*" %>
<%# page import="java.io.*" %>
<%
String sendmessage=(String)request.getAttribute("sendmessage");
if(sendmessage==null)
{
sendmessage="";
}
if (session == null) {
response.sendError(404, "Session expired");
return;
}
userinfo info = (userinfo)session.getAttribute("userinfo");
Folder folder=store.getFolder(info.getUrl());
int count = folder.getMessageCount();
int unread = folder.getUnreadMessageCount();
Integer messageno=Integer.parseInt(request.getParameter("messageno"));
Message[] message = folder.getMessages();
String ssubject=message[messageno].getSubject();
**//String from=message[messageno].getFrom()[0]; //program stops working when uncomment this line**
%>
<html><head>
<title>Home Page</title>
<link rel="stylesheet" type="text/css" href="styleforcomposemail.css" />
</head>
<body>
<center>
<form action='sendmail' method='post'>
<table>
<tr bgcolor='#800517'>
<td colspan='2'><b><h3><center>Compose Your Mail Here</center></h3></b></td>
</tr>
<tr height="15" bgcolor='#CFECEC'>
<td><b>From :</td>
<td><label for="login"><%= info.getsendfrom() %></label></td>
</tr>
<tr height="15" bgcolor='#CFECEC'>
<td><b>TO :</td>
<td><input type='text' name='sendto' class='Large' value='' /></b>Add "," For Sending Multiple Mails</td>
</tr>
<tr height="15" bgcolor='#CFECEC'>
<td><b >CC :</td>
<td><input type='text' name='cc' class='Large' /></b></td>
</tr>
<tr height="15" bgcolor='#CFECEC'>
<td><b>Subject :</td>
<td><input type='text' name='subject' class='Large' value='Re : <%=ssubject%>' /></td>
</tr>
<tr bgcolor='#CFECEC'>
<td colspan='2'><textarea id="textAreaa" onmouseover="javascript:setTextToTextArea('<%=data%>')" rows='32' cols='135' name='data' on>
Display Message Data here...come on..!!
</textarea></td>
</tr>
<tr height="15" bgcolor='#CFECEC'>
<td colspan='2'><input type='submit' class='button' name='Submit' value='Submit'/>
<input type='submit' class='button' name='Draft' value='Save As Draft'/>
<input type='reset' class='button' value='Reset' name='Reset'/>
<input type='reset' class='button' value='Discard' name='Reset'/>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
The getFrom() method returns an array of Address objects, not an array of Strings.
Try:
String from=message[messageno].getFrom()[0].toString();
Also, your program is missing all kinds of error handling. In particular,
some messages might not have a From address.
Another way to fetch data from forms is to create id of each field and get by getParameter(): request.getParameter("field-id");
Example: String subject = request.getParameter("subject");