I have this code where I am trying to send an email using JAVA Mail API. When running this code in eclipse, I am getting error as "Multiple annotations found at this line:Duplicate local variable session". I have declared session variable only once then why I am getting this error?
try{
String host="smtp.gmail.com";
String to="abc#gmail.com";
final String user="xyz#gmail.com";
final String password="*********";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host",host );
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);
}
});
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Thank you subscriber");
message.setContent("<table><tr><td>Name</td><td>+name+</td></tr><tr><td>Address</td><td>+Addr+</td></tr><tr><td>Age</td><td>+age+</td></tr><tr><td>Qualification</td><td>+Qual+</td></tr><tr><td>Percentage</td><td>+Persent+</td></tr><tr><td>Passout</td><td>+Year+</td></tr></table>","text/html");
Transport.send(message);
System.out.println("message sent....");
}
catch (MessagingException ex) {ex.printStackTrace();}
finally {}
This is my servlet which I am using.
package com.registration;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class RegistrationController
*/
public class RegistrationController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public RegistrationController() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name = request.getParameter("fullname");
String Addr = request.getParameter("address");
String age = request.getParameter("age");
String Qual = request.getParameter("qual");
String Persent = request.getParameter("percent");
String Year = request.getParameter("yop");
if(name.isEmpty()||Addr.isEmpty()||age.isEmpty()||Qual.isEmpty()||Persent.isEmpty()||Year.isEmpty())
{
RequestDispatcher rd = request.getRequestDispatcher("registration.jsp");
out.println("<font color=red>OOPS!! YOU MISSED OUT SOME FIELDS. FILL THEM AGAIN</font>");
rd.include(request, response);
}
else
{
RequestDispatcher rd = request.getRequestDispatcher("home.jsp");
rd.forward(request, response);
}
}
}
jsp has an inbuilt session variable that you can actually use. So since you are reusing it you are getting the duplicate error.
This is the equivalent of doing Session session=request.getSession() in a servlet;
Related
I am working with servlets as a newbie i have been trying to get desktop application and trying to see how they could come out when i use servlets,with the system.getproperty method if i hit my submit button i'm getting a blank message.
this is my jsp code.
<form action="checkservlet" method="get">
<input type="submit" value="submit"/><br/>
</form>
this is my servlet code
package com.check.pack;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class checkservlet
*/
#WebServlet("/checkservlet")
public class checkservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public checkservlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter write = response.getWriter();
Mulizwa Mcheck = new Mulizwa();
}
}
this is my class code
package com.check.pack;
import java.util.*;
public class Mulizwa {
public static void main(String[] args) {
Properties prop = System.getProperties();
Set<Object> keySet = prop.keySet();
for(Object obj : keySet){
System.out.println("System Property: {"+obj.toString()+","+System.getProperty(obj.toString())+"}");
}
}
}
i'm no expert but i'm here to learn,what i'm expecting from the code above if i hit the submit button i need to see the response in the browser about the system properties like os name java version etc.
First you need to write a function in your Mulizwa class that might return a String of your system properties instead of its main method that prints the properties on Standard out, some thing like this
public String getPropertyString (){
Properties prop = System.getProperties();
StringBuilder propertyString = new StringBuilder();
Set<Object> keySet = prop.keySet();
for(Object obj : keySet){
propertyString.append("System Property: {"+obj.toString()+","+System.getProperty(obj.toString())+"}");
}
return propertyString.toString();
}
Then in your servlet's doPost method,
PrintWriter write = response.getWriter();
Mulizwa mCheck = new Mulizwa();
write.write(mCheck.getPropertyString());
change
package com.check.pack;
import java.util.*;
public class Mulizwa {
public String getDetails(){
ResourceBundle rb = ResourceBundle.getBundle("System", Locale.getDefault());
StringBuilder str = new StringBuilder(" ");
Enumeration<String> en = rb.getKeys();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String value = rb.getString(key);
str.append(key+":"+value +"\n");
}
return sb.toString();
}
}
and in servelet class change doPost like the following
PrintWriter out = response.getWriter();
out.println(new Mulizwa().getDetails());
Instead of writing this code in main,keep it in a method in Mcheck class like this
public void writeSystemPropertiesInResponse(HttpServletResponse response)) {
Properties prop = System.getProperties();
Set<Object> keySet = prop.keySet();
PrintWriter writer = response.getWriter();
for(Object obj : keySet){
writer.write("System Property: {"+obj.toString()+","+System.getProperty(obj.toString())+"}");
}
}
And call this method in your servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
//PrintWriter write = response.getWriter();no need of this
Mulizwa Mcheck = new Mulizwa();
Mcheck.writeSystemPropertiesInResponse(resonse);
}
UPDATE
If you don't wanna pass response as argument,you can use StringBuilder to build a string and write using PrintWriter as suggested in other answers.
What I am trying to accomplish is trying to make a new customer in the my servlet when the user clicks submit on a form. The form is in the form of a jsp file. So when the user clicks submit it will go to the doPost method in the servlet. I want to add one to the customer id when I click submit also. No database is involved yet. Still learning concepts.
Errors are thrown everytime I click submit. Both the errors I have in the doPost are thrown.
How can I fix this
Servlet
package edu.witc.Assignment03.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import edu.witc.Assignment03.model.Customer;
import edu.witc.Assignment03.model.Phone;
import edu.witc.Assignment03.model.States;
#WebServlet(description = "servlet to get act as controller between form and models", urlPatterns = { "/customerServlet","/addCustomer","/addPet", "/customerManagement" })
public class CustomerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public CustomerServlet() {
super();
}
private List<edu.witc.Assignment03.model.Customer> customers = new ArrayList<Customer>();
private void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
Phone phone = new Phone();
States state = new States();
Collection<Phone> phones = phone.getPhoneCollection();
Collection<States> states = state.getStateCollection();
session.setAttribute("phones", phones);
session.setAttribute("states", states);
}
private void addCustomer(HttpServletResponse response, HttpServletRequest request)//redirect to form
throws IOException, ServletException {
String url = "/customerManagement.jsp";
processRequest(request, response);
Customer customer = new Customer();
HttpSession session = request.getSession();
session.setAttribute("customer", customer);
request.getRequestDispatcher(url).forward(request,response);
}
private void addPet(HttpServletResponse response, HttpServletRequest request)//redirect to pet page
throws IOException, ServletException {
String url = "/pets.jsp";
request.getRequestDispatcher(url).forward(request,response);
}
private Customer getCustomer(int customerId) {
for (Customer customer : customers) {
if (customer.getCustomerId() == customerId) {
return customer;
}
}
return null;
}
private void makeCustomerReceipt(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String url = "/receipt.jsp";
request.setAttribute("customers", customers);
request.getRequestDispatcher(url).forward(request,response);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
if("addCustomer".equals(action)) {
System.out.println("doGet add customer");
addCustomer(response, request);
}
else if("addPet".equals(action)) {
System.out.println("doGet pet");
addPet(response, request);
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// update customer
int customerId = 0;
Customer testCustomer = new Customer();
testCustomer.setCustomerId(1);
testCustomer.setFirstName("Test");
customers.add(testCustomer);
try {
customerId =
Integer.parseInt(request.getParameter("id"));
} catch (NumberFormatException e) {
response.getWriter().write("Error: Customer ID could not be parsed to a number");
}
Customer customer = getCustomer(customerId);
if (customer != null) {
customer.setFirstName(request.getParameter("firstName"));
customer.setLastName(request.getParameter("lastName"));
customer.setEmail(request.getParameter("email"));
customer.setPhone(request.getParameter("phone"));
customer.setAddress(request.getParameter("address"));
customer.setCity(request.getParameter("city"));
customer.setZip(request.getParameter("zip"));
makeCustomerReceipt(request, response);
}
else
{
response.getWriter().write("Error: customer is null");
}
}
}
I'm trying to build a simple gateway in Tomcat, which would do authorization checks and redirect the request to different endpoint, which gets the response and sends it back to the browser.
In Tomcat I have have a simple Servlet, which uses HttpURLConnection to connect to the endpoint, which gets the response and send it back to browser.
However in Chrome my URL always gets redirected to the endpoint domain. I don't see this behavior in IE or Firefox.
For example, this is deployed to hostname test.gateway.com.
If I make a http request test.gateway.com:9500/test/index.html from browser, Servlet should make a http request to test.endpoint.com/test/index.html and return the response. Client browser should remain on test.gateway.com:9500/test/index.html
However on Chrome my URL changes to http://test.endpoint.com/test/index.html
In my web.xml I have URL Mapping which calls this servlet.
Here is the Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class AppProxyServlet
*/
#WebServlet("/AppProxyServlet")
public class AppProxyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String proxy = "http://test.endpoint.com";
/**
* #see HttpServlet#HttpServlet()
*/
public AppProxyServlet() {
super();
// TODO Auto-generated constructor stub
}
private String callEndpoint(HttpServletRequest request, String plexURL)
throws Exception {
// make
String queryString = request.getQueryString();
if (queryString != null && queryString.length() > 0) {
plexURL += "?" + queryString;
}
URL obj = new URL(plexURL);
Cookie[] cookies = request.getCookies();
StringBuffer allCookies = new StringBuffer();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
// if( cookies[ i ].getName() == "SSO")
{
allCookies.append(cookies[i].getName());
allCookies.append("=");
if ("SSO".equals(cookies[i].getName())) {
String ssostr = cookies[i].getValue();
allCookies.append(ssostr);
} else {
allCookies.append(cookies[i].getValue());
}
if (i < cookies.length)
allCookies.append(";");
// con.setRequestProperty("Cookie", cookies[ i
// ].getName()+"="+cookies[i].getValue());
}
}
}
System.out.println("All Cookies:" + allCookies.toString());
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setInstanceFollowRedirects(false);
con.setRequestProperty("Accept-Charset", "ISO-8859-1");
con.setRequestProperty("Cookie", allCookies.toString());
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println("\nSending Get request to URL:" + plexURL);
System.out.println("Response code:" + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream(), "ISO-8859-1")); // iso-8859-1
int value;
StringBuffer response = new StringBuffer();
while ((value = in.read()) != -1) {
char c = (char) value;
response.append(c);
}
con.disconnect();
return (response.toString());
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// ServletContext sc = getServletContext();
StringBuilder URL = new StringBuilder("");
String URI = request.getRequestURI();
System.out.println("Full URL:" + URI);
// Form the URL
URL.append(proxy);
URL.append(URI);
String sspResponse = "";
if (URI.endsWith("css")) {
response.setContentType("text/css");
} else {
response.setContentType("text/html;charset=ISO-8859-1");
}
PrintWriter printWriter = response.getWriter();
try {
sspResponse = callEndPoint(request, URL.toString());
} catch (Exception e) {
System.out.println(e.getStackTrace());
System.out.println("Some exception occured...");
}
printWriter.println(sspResponse);
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
i have a login page which connects to a database for validation through a servlet.
in the servlet after successful login i'm using request dispatcher to login-success.html
here is the servlet code:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
/**
* Servlet implementation class DoLogin
*/
#WebServlet("/DoLogin")
public class DoLogin extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public DoLogin() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.println("<html>");
//Browser Back Button Disable Script After Logout
out.println("<script>");
out.println("javascript:window.history.forward(1)");
out.println("</script>");
out.println("<body style=\"background-color : rgb(41,85,153);\">");
//Invalidate The Session.
HttpSession session = request.getSession(false);
try
{
session.invalidate();
out.println("<h3><font family=\"Times New Roman\" color=\"white\">Successfully Logout</font></h3>");
out.println("<form action=\"/CloudMoV/login.html\" method=\"post\">");
out.println("<br />");
out.println("<input type=\"submit\" alt=\"submit\" value=\"Login Again!\"/>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
catch (Exception ee)
{
out.println(ee);
}
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// out.println("<html>");
// out.println("<head>");
// out.println("<title>");
// out.println("<html>");
// out.println("</title>");
// out.println("</head>");
// out.println("<body style=\"background-color : black;\">");
// connecting to database
Connection con = null;
Statement stmt = null;
ResultSet res = null;
//variable for checking the values true and false.
boolean success=false;
//creating session
HttpSession session = request.getSession(true);
try{
DbConnection db = new DbConnection();
con = db.connDb();
//Receiving Values From HTML FORM
String thisname=request.getParameter("username");
String thispwd=request.getParameter("password");
stmt = (Statement) con.createStatement();
//Query for selecting user name and password from database.
String q = "select username, password from register where username='"+thisname+"'";
res = stmt.executeQuery(q);
while(res.next())
{
if ((thisname.equals(res.getString("username"))) && (thispwd.equals(res.getString("password"))))
{
// out.println("<br /><br /><h3><font family=\"Times New Roman\" color=\"white\">You're successfully logged in. <br />Welcome "+res.getString("username")+"</font></h3>");
success = true;
}
}
}
catch (SQLException e)
{
throw new ServletException("Servlet Could not display records.", e);
}
catch (Exception e)
{
throw new ServletException("Exception.", e);
}
// if(success==true)
// {
// out.println("<font color=\"white\">session Id: " + session.getId() + "</font><br><br>");
// session.setAttribute("username", request.getParameter("username"));
//
// //Logout Button
// out.println("<form onclick=\"doGet("+request+","+ response+")\" >");
// out.println("<input type=\"submit\" value=\"logout\">");
// out.println("</form>");
// }
if(success==true)
{
session.setAttribute("username", request.getParameter("username"));
RequestDispatcher rd = request.getRequestDispatcher("/login-success.html");
rd.forward(request, response);
}
if(success==false)
{
// out.println("<br /><h3 style=\"text-align:center;color:#FFFFFF;margin-top:150px\">Invalid User Name or Password</h3>");
// out.println("<br /><h3 style=\"text-align:center;color:#FFFFFF;text-decoration:underline\">Go Back</h3>");
session.invalidate();
RequestDispatcher rd = request.getRequestDispatcher("/login.html");
rd.forward(request, response);
}
//
// out.println("</body>");
// out.println("</html>");
}
}
in the login-success i want to display the username. how do i do it?
i believe i should first change the login-success.html to login-success.jsp
You are setting user name value to session attribute "username" so you can use this EL expression ${sessionScope.username}
in your jsp. You should use it in jstl tag
Create http sesson and push login dto with user information and access the session variable from any jsp page and retrieve user/login information.thats it
After authentication success, set username attribute in session
session.setAttribute("loggedInUser_userName", userName);
Since HTML is static page, it needs ajax call to update page, Prefer JSP over HTML.
Use El Expression ${} to print username. No need of JSTL tag library for El Expression.
And in your username span
<span>${loggedInUser_userName}</span>
hi all I've typed out a page that queries the database then inputs something into the database but when I go to load the servlet/jsp page its comes back blank and am unsure what is happening or why? I'm coding in eclipse and after looking at the console and not getting anything printing out I figured there was something wrong with my code but I cannot see the problem.
Here is my servlet
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class TutorAssign
*/
#WebServlet("/TutorAssign")
public class TutorAssign extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public TutorAssign() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
private void sendBack(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
//Set data you want to send back to the request (will be forwarded to the page)
//Can set string, int, list, array etc.
String sql = "SELECT l.id,s.name,l.day,l.time,l.room" +
" FROM subject s, lab l " +
" WHERE s.user_id="+(Integer)session.getAttribute("id");
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/wae","root","");
System.out.println("got boobs");
System.out.println(session.getAttribute("id"));
Statement stmt = con.createStatement();
ResultSet res = stmt.executeQuery(sql);
System.out.println(res);
ArrayList<String> list1 = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();
if (res.next()){
do{
list1.add(res.getString(1));
list2.add(res.getString(2)+" "+res.getString(3)+" "+res.getString(4)+" "+res.getString(5));
}while(res.next());
System.out.println("Outside");
String[] arr1 = list1.toArray(new String[list1.size()]);
String[] arr2 = list2.toArray(new String[list2.size()]);
System.out.println(list1);
request.setAttribute("res1", arr1);
request.setAttribute("res2", arr2);
}
}catch (SQLException e) {
}
catch (Exception e) {
}
//Decides what page to send the request data to
RequestDispatcher view = request.getRequestDispatcher("TutorAssign.jsp");
//Forward to the page and pass the request and response information
view.forward(request, response);
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int user_id = Integer.parseInt(request.getParameter("id"));
int lab_id = 0;
String message = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/wae","root","");
System.out.println("got connection");
System.out.println(user_id);
Statement s = con.createStatement();
String sql = "INSERT INTO user_lab" +
" (user_id, lab_id)" +
" VALUES" +
" ('" + user_id + "'," +
" '" + lab_id + "')";
System.out.println(sql);
int i = s.executeUpdate(sql);
if (i==1) {
message = "Successfully assigned a tutor.";
response.sendRedirect("Lecturer_labs");
}
s.close();
con.close();
}
catch (SQLException e) {
message = "Error." + e.toString();
boolean error = true;
}
catch (Exception e) {
message = "Error." + e.toString();
boolean error = true;
}
if (message!=null) {
PrintWriter out = response.getWriter();
out.println("<B>" + message + "</B><BR>");
out.println("<HR><BR>");
}
}
// TODO Auto-generated method stub
}
I noticed that your doGet method has not been implemented.
I would assume that your sendBack code is not being called
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
sendBack(request,response);
}
You have several empty catch blocks. This means that if the program encounters some problem the error will be silently swallowed and you don't know what code got executed and what code was skipped, so the outcome is unknown. At least log the error in the catch block, like this (very basic example, using java.util.logging
} catch (SQLException e) {
logger.log(Level.INFO,"SQL Error encountered",e);
} catch (Exception e) {
logger.log(Level.INFO,"Other error encountered",e);
}
Start by getting your error handling right, and study the errors the program encounters.
Aside from that problem, as the others point out your doGet isn't implemented - so if you call the page with GET it won't do anything because doGet is empty. It should do something on POST though.