a href command not working

out.println("<TD><A HREF=DeleteServlet?id=" + id +">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?id=" + id +">Update</A></TD>");

I have a servlet, there is a textbox and a submit button. when a user enters a name his information is displayed in the table and right beside the information displayed in the table i should have a url named delete and update. if a user clicks delete it deletes the name from the database. if he clicks on update then user wil be able to enter information.

My servlet searchservlet page does not display the update and delte url. What am i doing wrong?

[769 byte] By [lrngjavaa] at [2007-11-27 6:32:38]
# 1
I think its better for both of us if you could show to us your servlet.
thunderbolta at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 2

[nobr]allrite. here is the original code. after hour of debugging i am able to display my url. now my problem is when i click on delete then my deleteservlet comes in action but for some reason its not deleting the information of the user, it displays the else statement error msg that Error in details.

here is my Searchservlet

package testing;

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.sql.*;

/**

* Servlet implementation class for Servlet: SearchServlet

*

*/

public class SearchServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

private String keyword = "";

public SearchServlet() {

super();

}

public void init() {

try {

Class.forName("org.apache.derby.jdbc.ClientDriver");

System.out.println("JDBC driver loaded");

}

catch (ClassNotFoundException e) {

System.out.println(e.toString());

}

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

sendPageHeader(response);

sendSearchForm(response);

sendPageFooter(response);

}

/* (non-Java-doc)

* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

keyword = request.getParameter("keyword");

sendPageHeader(response);

sendSearchForm(response);

sendSearchResult(response);

sendPageFooter(response);

}

void sendSearchResult(HttpServletResponse response)

throws IOException {

PrintWriter out = response.getWriter();

try {

Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

System.out.println("got connection");

Statement s = con.createStatement();

out.println("<TABLE>");

out.println("<TR>");

out.println("<TH>First Name</TH>");

out.println("<TH>Last Name</TH>");

out.println("<TH>User Name</TH>");

out.println("<TH>Password</TH>");

out.println("</TR>");

String sql = "SELECT FirstName, LastName, UserName, Password" +

" FROM USERS.posts" +

" WHERE FirstName LIKE '%" + fixSqlFieldValue(keyword) + "%'" +

" OR LastName LIKE '%" +fixSqlFieldValue(keyword) + "%'";

ResultSet rs = s.executeQuery(sql);

while (rs.next()) {

String id = rs.getString(1);

out.println("<TR>");

out.println("<TD>" + encodeHtmlTag(rs.getString(2)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(3)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(4)) + "</TD>");

out.println("<TD><A HREF=DeleteServlet?id= " + id + ">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?id= " +id + ">Update</A></TD>");

out.println("</TR>");

}

s.close();

con.close();

}

catch (SQLException e) {

}

catch (Exception e) {

}

out.println("</TABLE>");

}

/**

* Send the HTML page header, including the title

* and the <BODY> tag

*/

private void sendPageHeader(HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<HTML>");

out.println("<HEAD>");

out.println("<TITLE>Displaying Selected Record(s)</TITLE>");

out.println("</HEAD>");

out.println("<BODY>");

out.println("<CENTER>");

}

/**

* Send the HTML page footer, i.e. the </BODY>

* and the </HTML>

*/

private void sendPageFooter(HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

out.println("</CENTER>");

out.println("</BODY>");

out.println("</HTML>");

}

/**Send the form where the user can type in

* the details for a new user

*/

private void sendSearchForm(HttpServletResponse response)

throws IOException {

PrintWriter out = response.getWriter();

out.println("<BR><H2>Search Form</H2>");

out.println("<BR>Please enter the first name, last name or part of any.");

out.println("<BR>");

out.println("<BR><FORM METHOD=POST>");

out.print("Name: <INPUT TYPE=TEXT Name=keyword");

// out.println(" VALUE=\"" + encodeHtmlTag(keyword) + "\"");

out.println(">");

out.println("<INPUT TYPE=SUBMIT>");

out.println("</FORM>");

out.println("<BR>");

out.println("<BR>");

}

public static String encodeHtmlTag(String tag) {

if (tag==null)

return null;

int length = tag.length();

StringBuffer encodedTag = new StringBuffer(2 * length);

for (int i=0; i<length; i++) {

char c = tag.charAt(i);

if (c=='<')

encodedTag.append("&lt;");

else if (c=='>')

encodedTag.append(">");

else if (c=='&')

encodedTag.append("&");

else if (c=='"')

encodedTag.append("""); //when trying to output text as tag's value as in

// values="?".

else if (c==' ')

encodedTag.append(" ");

else

encodedTag.append(c);

}

return encodedTag.toString();

}

public static String fixSqlFieldValue(String value) {

if (value==null)

return null;

int length = value.length();

StringBuffer fixedValue = new StringBuffer((int) (length * 1.1));

for (int i=0; i<length; i++) {

char c = value.charAt(i);

if (c=='\'')

fixedValue.append("''");

else

fixedValue.append(c);

}

return fixedValue.toString();

}

}

and here is my DeleteServlet

package testing;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.sql.*;

public class DeleteServlet extends HttpServlet {

/**Process the HTTP Get request*/

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {

int recordAffected = 0;

try {

String id = request.getParameter("id");

String sql = "DELETE FROM USERS.posts WHERE post_id=" + id;

Connection con =

DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

Statement s = con.createStatement();

recordAffected = s.executeUpdate(sql);

s.close();

con.close();

}

catch (SQLException e) {

}

catch (Exception e) {

}

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("><HTML>");

out.println("<HEAD>");

out.println("<TITLE>Deleting A Record</TITLE>");

out.println("</HEAD>");

out.println("<BODY>");

out.println("<CENTER>");

if (recordAffected==1)

out.println("<P>Record deleted.</P>");

else

out.println("<P>Error deleting record.</P>");

out.println("<A HREF=SearchServlet>Go back</A> to the Search page");

}

}

and here is my sql scratchpage

CREATE TABLE USERS.posts (

post_id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),

FirstName VARCHAR(20),

LastName VARCHAR(20),

UserName VARCHAR(20),

Password VARCHAR(20));

Thanks[/nobr]

lrngjavaa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 3
it appears to throw exception and since you make that throws silent, you don't get any exception.} catch (Exception e) {}
j_shadinataa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 4
no its notcatch (SQLException e) {System.out.println(e.toString());}no exception
lrngjavaa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 5
catch (Exception e) {System.out.println(e.toString());}
lrngjavaa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 6

try print out your sql before you execute it.

System.out.println(sql);

rowAffected = stm.executeUpdate(sql);

& its better to print exception message than call to string method.

} catch (SQLException sqlEx) {

System.out.println(sqlEx.getMessage());

} catch ...

j_shadinataa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 7

another guess...

String sql = "SELECT FirstName, LastName, UserName, Password" +

" FROM USERS.posts" +

" WHERE FirstName LIKE '%" + fixSqlFieldValue(keyword) + "%'" +

" OR LastName LIKE '%" +fixSqlFieldValue(keyword) + "%'";

ResultSet rs = s.executeQuery(sql);

while (rs.next()) {

String id = rs.getString(1);

your id actully hold first name value... but when you execute the delete, it should throw sqlexception since your sql sintax become incorrect...

j_shadinataa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 8

No Exceptions nothing. The program is fine except it does not delete the data when i click on the delete url beside the information table which is displayed. one thing i noticed is when i click on delete this is the url in my browser.

http://localhost:8080/chapter4/DeleteServlet?id=

as you can see it is suppose to be like

http://localhost:8080/chapter4/DeleteServlet?id=2

or 1 or 3 depending on the id number assigned to the user which is a primary key as i have shown earlier.

Either my String id = rs.getString(1); is not correct. I am still stuggling thanks for the effor though.

lrngjavaa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 9

hmmm good point. i knew something was wrong but i have posts_id as a primary key and then firstName, lastName and password. i thought if i do rs.getString(1) then my Id in the database will get executed.

How can i change my statement so it knows to delete the id which is assigned to a user.

Secondly i thought to change the whole syntax like i would like to get rid of ID and replacing it with firstName, still the same thing.

lrngjavaa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 10

> Either my String id = rs.getString(1); is not correct. I am still stuggling > thanks for the effor though.

yes.. read my previous reply. what you store in id variable is first name not post id. and from your browser url result, i think you work with empty string data in first name.

j_shadinataa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 11

ok i did this

while (rs.next()) {

String firstname = rs.getString(1);

out.println("<TR>");

out.println("<TD>" + encodeHtmlTag(rs.getString(1)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(2)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(3)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(4)) + "</TD>");

out.println("<TD><A HREF=DeleteServlet?firstname= " + firstname + ">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?firstname= " +firstname + ">Update</A></TD>");

out.println("</TR>");

}

and this in my deleteServlet

try {

String firstname = request.getParameter("firstname");

String sql = "DELETE FROM USERS.posts WHERE FirstName=" + firstname;

Connection con =

DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

Statement s = con.createStatement();

recordAffected = s.executeUpdate(sql);

s.close();

con.close();

}

still it does not make any difference

lrngjavaa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 12

just repair your sql query that display search result to this:

// add post_id

String sql = "SELECT post_id, FirstName, LastName, UserName, Password" +

" FROM USERS.posts" +

" WHERE FirstName LIKE '%" + fixSqlFieldValue(keyword) + "%'" +

" OR LastName LIKE '%" +fixSqlFieldValue(keyword) + "%'";

your response writing seems ok, since it only print from column 2 (now become first name).

give a try!

j_shadinataa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 13

FirstName is a string you need to put it like this

try {

String firstname = request.getParameter("firstname");

String sql = "DELETE FROM USERS.posts WHERE FirstName='" + firstname +"'";

Connection con =

DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

Statement s = con.createStatement();

recordAffected = s.executeUpdate(sql);

s.close();

con.close();

}

Nightman150a at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 14

your solution can work when your first name are unique. even if your first name data are unique, i recommend you to use post_id as primary key. in real world, we will meet many person with same first name.

in case your first name are unique. you should aware that first name data type is string/varchar not integer. you can adding quote in beginning and end of that varchar, but i recommend you to use PreparedStatement.

Message was edited by:

j_shadinata

j_shadinataa at 2007-7-12 17:58:14 > top of Java-index,Java Essentials,New To Java...
# 15

I know you're just beginning but 3 key things...

1. Use PreparedStatements EVERYWHERE, to avert [url=http://en.wikipedia.org/wiki/SQL_Injection]SQL-Injection[/url]

What happens to your website if I enter my name as "t' or 1=1 or 't" and then delete it?

2. HTML encode all display fields

What happens to your site if I enter my name as "<FRAME><APPLET= ....

3. URL encode all paramaters (and not the whole URL string).

What happens if I enter my name as "J&J Jimbo Jay Billy Bob" (I mean, apart from obviously leaving a trail of empty Bourbon & Cola cans).

Message was edited by: corlettk>

corlettka at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 16

ok thanks shadinata. it worked. how stupid of me ah... bad. anyways thanks.

Yes i am using post_id thing. but now still the record is not deleting.

String sql = "SELECT post_id, FirstName, LastName, UserName, Password" +

" FROM USERS.posts" +

" WHERE FirstName LIKE '%" + fixSqlFieldValue(keyword) + "%'" +

" OR LastName LIKE '%" +fixSqlFieldValue(keyword) + "%'";

System.out.println(sql);

ResultSet rs = s.executeQuery(sql);

while (rs.next()) {

String id = rs.getString(1);

out.println("<TR>");

....

and this is my deleteservlet

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {

int recordAffected = 0;

try {

String id = request.getParameter("id");

String sql = "DELETE FROM USERS.posts WHERE post_id =" + id ;

// String sql = "DELETE FROM Users WHERE Id=" + id;

Connection con =

DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

Statement s = con.createStatement();

System.out.println(sql);

recordAffected = s.executeUpdate(sql);

s.close();

con.close();

}

catch (SQLException e) {

System.out.println(e.getMessage());

}

catch (Exception e) {

}

still my else statement executes.

lrngjavaa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 17
ok corltekk i will look into it. Thanks
lrngjavaa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 18

try print your sql variable to trace.

String id = request.getParameter("id");

String sql = "DELETE FROM USERS.posts WHERE post_id =" + id ;

System.out.println(sql);

my guess is you passing that id value not correctly. please post your response code when printing search result.

(Edit) oh... sorry, you did it. what your sql value when you print it.

Message was edited by:

j_shadinata

j_shadinataa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 19

this is my stack trace

DELETE FROM USERS.posts WHERE post_id =

Syntax error: Encountered "<EOF>" at line 1, column 39.

still the id in my URL is empty. if i try the other way

String sql = "DELETE FROM USERS.posts WHERE post_id = '" + id + "'";

still no success but here is the stack trace if i use the above sql statement

DELETE FROM USERS.posts WHERE post_id = ''

Comparisons between 'INTEGER' and 'CHAR' are not supported.

lrngjavaa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 20

what result you get from this statment?

System.out.println(sql);

please post your new code that render result set to html table.

while (rs.next()) {

String firstname = rs.getString(1);

out.println("<TR>");

out.println("<TD>" + encodeHtmlTag(rs.getString(1)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(2)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(3)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(4)) + "</TD>");

out.println("<TD><A HREF=DeleteServlet?firstname= " + firstname + ">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?firstname= " +firstname + ">Update</A></TD>");

out.println("</TR>");

}

j_shadinataa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 21

DELETE FROM USERS.posts WHERE post_id =

Syntax error: Encountered "<EOF>" at line 1, column 39.

line 1 tells, when you call id = getParameter("id") return empty string.

line 2 is sql exception message means your sql syntax is wrong.

what url you see at your browser? http://localhost.../DeleteServlet?id=2?

j_shadinataa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 22
no this is what i see. http://localhost:8080/chapter4/DeleteServlet?id=something is wrong with the id but i dont see anything wrong in the sql statement?
lrngjavaa at 2007-7-21 21:58:04 > top of Java-index,Java Essentials,New To Java...
# 23

i think your delete servlet is okay. the problem may cause from search servlet.

please post your new code that render result set to html table.

while (rs.next()) {

String firstname = rs.getString(1);

out.println("<TR>");

out.println("<TD>" + encodeHtmlTag(rs.getString(1)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(2)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(3)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(4)) + "</TD>");

out.println("<TD><A HREF=DeleteServlet?firstname= " + firstname + ">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?firstname= " +firstname + ">Update</A></TD>");

out.println("</TR>");

}

in previous code you supply a space character before first name value. so post your current code. i think you doing same mistake.

j_shadinataa at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 24

[nobr]package testing;

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.sql.*;

/**

* Servlet implementation class for Servlet: SearchServlet

*

*/

public class SearchServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

private String keyword = "";

public SearchServlet() {

super();

}

public void init() {

try {

Class.forName("org.apache.derby.jdbc.ClientDriver");

System.out.println("JDBC driver loaded");

}

catch (ClassNotFoundException e) {

System.out.println(e.toString());

}

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

sendPageHeader(response);

sendSearchForm(response);

sendPageFooter(response);

}

/* (non-Java-doc)

* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

keyword = request.getParameter("keyword");

sendPageHeader(response);

sendSearchForm(response);

sendSearchResult(response);

sendPageFooter(response);

}

void sendSearchResult(HttpServletResponse response)

throws IOException {

PrintWriter out = response.getWriter();

try {

Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

System.out.println("got connection");

Statement s = con.createStatement();

out.println("<TABLE>");

out.println("<TR>");

out.println("<TH>First Name</TH>");

out.println("<TH>Last Name</TH>");

out.println("<TH>User Name</TH>");

out.println("<TH>Password</TH>");

out.println("</TR>");

String sql = "SELECT post_id, FirstName, LastName, UserName, Password" +

" FROM USERS.posts" +

" WHERE FirstName LIKE '%" + fixSqlFieldValue(keyword) + "%'" +

" OR LastName LIKE '%" +fixSqlFieldValue(keyword) + "%'";

System.out.println(sql);

ResultSet rs = s.executeQuery(sql);

while (rs.next()) {

String id = rs.getString(1);

out.println("<TR>");

out.println("<TD>" + encodeHtmlTag(rs.getString(1)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(2)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(3)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(4)) + "</TD>");

out.println("<TD>" + encodeHtmlTag(rs.getString(5)) + "</TD>");

out.println("<TD><A HREF=DeleteServlet?id= " + id + ">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?id= " +id + ">Update</A></TD>");

out.println("</TR>");

}

s.close();

con.close();

}

catch (SQLException e) {

System.out.println(e.getMessage());;

}

catch (Exception e) {

System.out.println(e.getMessage());

}

out.println("</TABLE>");

}

/**

* Send the HTML page header, including the title

* and the <BODY> tag

*/

private void sendPageHeader(HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<HTML>");

out.println("<HEAD>");

out.println("<TITLE>Displaying Selected Record(s)</TITLE>");

out.println("</HEAD>");

out.println("<BODY>");

out.println("<CENTER>");

}

/**

* Send the HTML page footer, i.e. the </BODY>

* and the </HTML>

*/

private void sendPageFooter(HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

out.println("</CENTER>");

out.println("</BODY>");

out.println("</HTML>");

}

/**Send the form where the user can type in

* the details for a new user

*/

private void sendSearchForm(HttpServletResponse response)

throws IOException {

PrintWriter out = response.getWriter();

out.println("<BR><H2>Search Form</H2>");

out.println("<BR>Please enter the first name, last name or part of any.");

out.println("<BR>");

out.println("<BR><FORM METHOD=POST>");

out.print("Name: <INPUT TYPE=TEXT Name=keyword");

// out.println(" VALUE=\"" + encodeHtmlTag(keyword) + "\"");

out.println(">");

out.println("<INPUT TYPE=SUBMIT>");

out.println("</FORM>");

out.println("<BR>");

out.println("<BR>");

}

public static String encodeHtmlTag(String tag) {

if (tag==null)

return null;

int length = tag.length();

StringBuffer encodedTag = new StringBuffer(2 * length);

for (int i=0; i<length; i++) {

char c = tag.charAt(i);

if (c=='<')

encodedTag.append("&lt;");

else if (c=='>')

encodedTag.append(">");

else if (c=='&')

encodedTag.append("&");

else if (c=='"')

encodedTag.append("""); //when trying to output text as tag's value as in

// values="?".

else if (c==' ')

encodedTag.append(" ");

else

encodedTag.append(c);

}

return encodedTag.toString();

}

public static String fixSqlFieldValue(String value) {

if (value==null)

return null;

int length = value.length();

StringBuffer fixedValue = new StringBuffer((int) (length * 1.1));

for (int i=0; i<length; i++) {

char c = value.charAt(i);

if (c=='\'')

fixedValue.append("''");

else

fixedValue.append(c);

}

return fixedValue.toString();

}

}

Thanks>[/nobr]

lrngjavaa at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 25

out.println("<TD><A HREF=DeleteServlet?id= " + id + ">Delete</A></TD>");

out.println("<TD><A HREF=UpdateServlet?id= " +id + ">Update</A></TD>");

as i said before. read carefully my previous reply.

j_shadinataa at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 26
space is not making any difference. still give me the same thing.
lrngjavaa at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 27
check your html code. and post that <a href ...> tag.
j_shadinataa at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 28

[nobr]this is my html code.

<HTML>

<HEAD>

<TITLE>Displaying Selected Record(s)</TITLE>

</HEAD>

<BODY>

<CENTER>

<BR><H2>Search Form</H2>

<BR>Please enter the first name, last name or part of any.

<BR>

<BR><FORM METHOD=POST>

Name: <INPUT TYPE=TEXT Name=keyword VALUE="khan"

>

<INPUT TYPE=SUBMIT>

</FORM>

<BR>

<BR>

<TABLE>

<TR>

<TH>First Name</TH>

<TH>Last Name</TH>

<TH>User Name</TH>

<TH>Password</TH>

</TR>

<TR>

<TD>2</TD>

<TD>imran</TD>

<TD>khan</TD>

<TD>khan123</TD>

<TD>khan</TD>

<TD><A HREF=DeleteServlet?id= 2>Delete</A></TD>

<TD><A HREF=UpdateServlet?id= 2>Update</A></TD>

</TR>

<TR>

<TD>4</TD>

<TD>imran</TD>

<TD>khan</TD>

<TD>imran</TD>

<TD>khan</TD>

<TD><A HREF=DeleteServlet?id= 4>Delete</A></TD>

<TD><A HREF=UpdateServlet?id= 4>Update</A></TD>

</TR>

</TABLE>

</CENTER>

</BODY>

</HTML>

[/nobr]

lrngjavaa at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 29
wow.. if this qualifies as "New To Java" then i think im in trouble.. just wondering.. how long have you been working with java?
G-Dub_Sama at 2007-7-21 21:58:05 > top of Java-index,Java Essentials,New To Java...
# 30
lol one year. well actually servlet forums are way too slow. so if i have any problems in servlets or jsp i do post in new to java since alot of people do look in these forums.
lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 31
<TD><A HREF=DeleteServlet?id= 2>Delete</A></TD><TD><A HREF=UpdateServlet?id= 2>Update</A></TD>that is the problem! since it is a space like my posts before.Message was edited by: j_shadinata
j_shadinataa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 32
exatcly but i dont see anything wrong with my code or any space then why html is generating this space?
lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 33

find the difference:

"<TD><A HREF=DeleteServlet?id= " + id + ">Delete</A></TD>"

"<TD><A HREF=DeleteServlet?id=" + id + ">Delete</A></TD>"

j_shadinataa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 34
find the difference? sorry i did'nt get you.
lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 35

// your wrong code

"<TD><A HREF=DeleteServlet?id= " + id + ">Delete</A></TD>"

// should be like this

"<TD><A HREF=DeleteServlet?id=" + id + ">Delete</A></TD>"

j_shadinataa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 36
shadinata can i give you a big kiss ? ;--) It worked... Yayyy... Thanks alot. but why ? i mean this is ridiculous? it does not make any sense. looks to me like the compiler is very picky.
lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 37

> shadinata can i give you a big kiss ? ;--)

>

> It worked... Yayyy... Thanks alot. but why ? i mean

> this is ridiculous? it does not make any sense. looks

> to me like the compiler is very picky.

Errr no. Nothing to do with the compiler.

The program is printing exactly what you told it to. The part in the quotes. You had a space in the quotes. It was printed.

cotton.ma at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 38

cotton hey. but i tried everything. i understand what shadinta was talking about. i did exatcly what he said. space + no space. i tried different senarios but was not successful. err. so while updating or deleting a record from a database we had to be careful about the spaces.

That sucks i mean i was stuck for one whole day lol thanks to shadinta for helping me out, cannot believe it was a space problem. errr

Any other ideas or any other suggestions while doing servlet programming? i have'nt gone to jsp yet but when i do i will do all my html programming in jsp. i think its better to write all the html commands in jsp.

lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 39
> i have'nt gone to jsp yet but> when i do i will do all my html programming in jsp. i> think its better to write all the html commands in> jsp.This sounds very wise.
cotton.ma at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 40
> shadinata can i give you a big kiss ? ;--) in reality, u can't =)
j_shadinataa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 41
thanks. i learned alot from these forums and thanks for helping. i am trying to get used to of using PreparedStatement. Let me see if i will be able to achieve it.
lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 42
ur welcome
j_shadinataa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 43

> thanks. i learned alot from these forums and thanks

> for helping. i am trying to get used to of using

> PreparedStatement. Let me see if i will be able to

> achieve it.

Speaking of that. You inspired me to write an article for the SDN share

thing.

http://www.sdnshare.com/view.jsp?id=525

cotton.ma at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 44

> > shadinata can i give you a big kiss ? ;--)

> in reality, u can't =)

hehe thanks alot man. for helping me out. i really appreciate it. hope to give this favor back to you some day ..

email me if you want me to complete any kind of java program or help you in projects(i doubt if you need any help). i am willing to spend time on it.

Message was edited by:

lrngjava

lrngjavaa at 2007-7-21 21:58:10 > top of Java-index,Java Essentials,New To Java...
# 45
imgjava,You really do not want to post your email address here.you are likely to get alot of spam to it. I did not reply to that post in the hope that you will still be able to edit it.
cotton.ma at 2007-7-21 21:58:15 > top of Java-index,Java Essentials,New To Java...
# 46

> > thanks. i learned alot from these forums and

> thanks

> > for helping. i am trying to get used to of using

> > PreparedStatement. Let me see if i will be able to

> > achieve it.

>

> Speaking of that. You inspired me to write an article

> for the SDN share

> thing.

>

> http://www.sdnshare.com/view.jsp?id=525

Wonderful. I have already added that SDn share to my favorites list. Hope some people can write more good articles like this one from which we can take advantage and can understand it properly.

lrngjavaa at 2007-7-21 21:58:15 > top of Java-index,Java Essentials,New To Java...
# 47

> imgjava,

>

> You really do not want to post your email address

> here.

>

> you are likely to get alot of spam to it. I did not

> reply to that post in the

> hope that you will still be able to edit it.

lol thanks. Done.

lrngjavaa at 2007-7-21 21:58:15 > top of Java-index,Java Essentials,New To Java...