fankoff 0 Newbie Poster

One last question, really !


How for goodness's sake can I load the results in the html page without leaving it? Always when I click a button (do I always have to click a button? is there a way to call a resultset from the html and to handle it there?), I get redirected to the jsp that carries out the action.

I`ve tried putting the <jsp: forward> tag at the bottom of the jsp, so when it is done with processing the db-results to redirect back to the calling-page.

still no success on this one. for 3 days now, and my time is ticking away....


please help me. thanks a million!

fankoff 0 Newbie Poster

It simply wont forward my page!
I`ve tried everything, and it still wont forward it.


Basically what I have is a register.html where the user can put his username, passwort, etc. , a db_register.jsp which handles the input and sends it to the appropriate tables in the db.

When the user clicks on the button "register!" the html form uses the jsp, which is a blank html page with all the <% jsp-instructions %>

So I first tried to put the following at the end of the register.jsp:

<%
         < jsp:forward page="/myProfile.html" >
	 <jsp:param name="username" value=username /> 
	 <jsp:param pass="pass" value=password/>
	 </jsp:forward>
%>

NOTHING.
Then I put it in the register.hmtl.

NOTHING.

This is such a simple thing, and I`m trying to work it out for the whole day!!!!
Please help me before it is too late :( ! :(

Thank you in advance !

fankoff 0 Newbie Poster

Hallo guys,

a theoretical question I have there for you.
I have a search form in HTML with several input fields, so the user can search for particular features in a db.

My queiston: How can I generate a dynamic query, depending on which fields the user had filled in?

It should look like this:

>look at the input fields:
>if request.getParameter("art) !=null : Query + age
>if request.getParameter("experience") !=0 : + Query + experience
>if request.getParameter("instrument") != null: Query + instrument
> .... and so on

>final query = SELECT art, experience,instrument FROM x, y, z WHERE x.art = art AND y.experience experience AND z.instrument LIKE '%instrumen%' ;

I hope I have explained it somewhat understandable.

Any help is deeply appreciated! Thank you in advance...
fankoff

fankoff 0 Newbie Poster

Ok, I got it now!

if( resQuery != null ) {
    	out.println("<TR>");
 
    	try{
    		int numOfColumns = resQuery.getMetaData().getColumnCount();
 
    	 	for(int k=1;k<=numOfColumns;k++){
 
    		out.println("<TD>" + resQuery.getMetaData().getColumnName(k) +"</TD>");
     	}
    	 	out.println("<TR>");
 
    	while(resQuery.next()){
    		for(int k=1;k<=numOfColumns;k++){
        	 	out.println("<TD><b>"+resQuery.getString(resQuery.getMetaData().getColumnName(k))+"</TD>");
    			}
                [B][I] out.println("</TR>");[/I][/B]
    	 	}
 
    		
    	}catch (Exception e) {e.printStackTrace(); }

I`m sorry for the thread, but I`m sure this would be useful for other novice as me ;)

cheers

fankoff 0 Newbie Poster

So basically what I`ve ended up with is the follwing:

if( resQuery != null ) {
    	out.println("<TR>");
    		
    	try{
    		int numOfColumns = resQuery.getMetaData().getColumnCount();
    	 	
    	 	for(int k=1;k<=numOfColumns;k++){
    	 	
    		out.println("<TD>" + resQuery.getMetaData().getColumnName(k) +"</TD>");
     	}
    	 	out.println("<TR>");
    	 	
    	while(resQuery.next()){
    		for(int k=1;k<=numOfColumns;k++){
        	 	out.println("<TD><b>"+resQuery.getString(resQuery.getMetaData().getColumnName(k))+"</TD>");
    			}
    	 	}
    	
    		out.println("</TR>");
    	}catch (Exception e) {e.printStackTrace(); }

Is this logically ok? It works, but it doesn`t display the result properly. Where could be the problem?

fankoff 0 Newbie Poster

Ok, I found the solution for the first question:
....
out.println("<TD>" + resQuery.getMetaData().getColumnName(k) +"</TD>");

So please give me some help about the second one:
out.println("<TR><TD><b>"+resKname+"</TD><TD>"+resTalent+"</TD><TD>"+resStyle+"</TD><TD>"+resInstrument+"</TD><TD>"+resExperience+"</TD><TD>"+resRating+"</TD><TD>"+resStatus+"<.. ..
how can I make this change dynamically and to not have to print all the values (most of which would be null)?

fankoff 0 Newbie Poster

I`ve just noticed, this should also regard the part where the actual values are filled in the table under the appropriate table heading.

How do I then say: "give only these values, that are in the table"

Now I`m printing all the possible values that could be contained in a resultset and when it doesnt find them, it of course crashes.

out.println("<TR><TD><b>"+resKname+"</TD><TD>"+resTalent+"</TD><TD>"+resStyle+"</TD><TD>"+resInstrument+"</TD><TD>"+resExperience+"</TD><TD>"+resRating+"</TD><TD>"+resStatus+"</TD></TR>");


Thanks a lot!

fankoff 0 Newbie Poster

Hi guys,

I have a quick and interesting question there for you:

I have my DB and a execute a query to read some data from the DB and return it to the HTML.
The data that is returned depends on the search fields the user had filled in.
So if he had only filled lets say Experience and rating out of several possible fields, the query would produce a table containing just these two parameters.

Now, when I fetch my result, I want to read the names of the columns that the query returned, in order to write them in the html as table headings. How do I do this?


Here simple structure of what I mean:

resultSet resQuery = null;
resQuery = stmt.executeQuery(searchQuery);

 if( resQuery != null ) {
    	out.println("<TR>");
    		
    	try{
    	while(resQuery.next()) {
    		out.println("<TD>" + resQuery.[I]getNext()[/I] +"</TD>");
    	}        
       out.println("</TR>");

 // and then when the HTML table has the appropriate headings, let the values flow into the table

    	while(resQuery.next()) {
    			String resKname = null;		
    			String resTalent = null;
    			String resStyle = null;
    			String resInstrument=null;
    			int resExperience=0;
                        ..............
out.println("<TR><TD><b>"+resKname+"</TD><TD>"+resTalent+"</TD><TD>"+resStil+"</TD>......
}

This shouldn't be that difficult?

fankoff 0 Newbie Poster

Then provide the exception you're getting.

no exeptions occur. I start the login.html, fill in the fields, click submit and I get the blan page with this one line :

" Trying Connection......Making Query"


no "processing results", no "getting data", no redirections, no nothing.

As if the compiler stops at the line, before/after the query has been made.

fankoff 0 Newbie Poster

Thank you Masijade, your suggestion was the solution for the finally problem. Nevertheless, the rest also doesnt work, although it makes absolut sense to me.

fankoff 0 Newbie Poster

Ok, let me show you my whole code, because it appears to not function at all.
This should be a simple login action, where username and password are validated. nothing more, nothing less.

<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page language="java" session="true" %>
 <%@ include file="basic_einloggen.jsp" %>
 

<%
		//Getting the text values from create login page
		String kuname   = request.getParameter("kuname");
		String passwort  = request.getParameter("passwort");
   
        String loginid  = kuname.trim();
	    String loginpin = passwort.trim();
        
	    
       Connection conn;
       Statement stmt;
       ResultSet resDisplay;
       ResultSet resInsert;
        
		
        String id  =  null;
	String pin =  null;
		
	try{

	out.println("TRYING Connection......");
			
	Class.forName("org.postgresql.Driver");        
	conn = DriverManager.getConnection(dburl);     
           

	out.println("Making Query......);

	String sql = "SELECT * FROM Login WHERE userID='"+loginid+"'";
	stmt = conn.createStatement();
	resInsert = stmt.executeQuery(sql);
				
	out.println("PROCESSING RESULTS......");
				
		while( resInsert.next() )
		{
			out.println("READING DATA......");
			
			id =  resInsert.getString("loginid");
			pin = resInsert.getString("passwort");
			
		    /// pin = resInsert.getString("passwort");
			// id  = resInsert.getString("loginid");
			  
			// pin.trim();
			 //id.trim();
			 
			 out.println(id);
			 out.println(pin);
			 
			 //i++;
		}

		
	
	 	
	 	if(loginid.equals(id) && loginpin.equals(pin))
		{
	         out.println("login successful");
		 %>
		 <jsp:forward page="/I_am_anArtist.htm"></jsp:forward>
		 <% 
        }
		else
		{
           out.println("incorrect username/password combination");
           %>
  		 <jsp:forward page="/login.html"></jsp:forward>
  		 <% 
		}
	 	
		}
        
        
    	catch(Exception e){e.printStackTrace();}
    	
    	finally{
            try{
               	
            	if(resInsert !=null){
            		stmt.close();
            	}
                
                if(stmt !=null){
                	stmt.close();
                }
                   
                if(conn != null){
                    conn.close();
                }
            }
            catch(Exception e2){
                out.println("Unable to close connection: "+e2.getMessage());
            }
         }
%>

The reason why I`ve used out.printlns so much is beacuse I wanted to follow where the code breaks.
And I only get this : "TRYING Connection......Making Query......

And to get this message at all, I have to completely remove the finally-block, because of the error I depicted above.


And yes, …

fankoff 0 Newbie Poster

How could I like programming ?

When you spend 2 days on one single, pointless line and the only thing you get to see is an ERROR-response. It`s really inhuman and I cant imagine who would want this voluntarily.

Nevertheless, what am I yammering about is following error, that is absolutely god-awful:

<body>


<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page language="java" session="true" %>
 <%@ include file="basic_login.jsp" %>
 
<%
java.sql.Connection conn;
        java.sql.Statement stmt;
        java.sql.ResultSet resDisplay;
        java.sql.ResultSet resInsert;

try{

			out.println("TRYING......");
			
			 Class.forName("org.postgresql.Driver");        
		        conn = DriverManager.getConnection(dburl);   

 /// variables definition and commands follow

} 

catch(Exception e){e.printStackTrace();}
    	
    	finally{
            try{
                if(resInsert != null){
                    resInsert.close();
                }
                
                if(stmt !=null){
                	stmt.close();
                }
                   
                if(conn != null){
                    conn.close();
                }
            }
            catch(Exception e2){
                out.println("Unable to close connection: "+e2.getMessage());
            }
         }
%>

SO. I run the html that uses this JSP, fill in the fields, press the submit button and, oh wonder, an error comes along. Well what does this failure says? A simple :

The local variable resInsert may not have been initialized
105: if(resInsert != null){


The f* variable is DEFINITELY INITIALIZED, right at the beginning:
java.sql.ResultSet resInsert; and has been worked with all the way in the <% code %>
and then suddenly at the end, it occurs to the compiler, that the variable is not initialized?

Such things make me very angry. awfully angry.

WHY ?


P.S. I`ve just removed this line and it goes on with the next one saying:
The …

fankoff 0 Newbie Poster

Hi guys,

I`m new to web-developing. Curruntly I`m battling with JSP and Databases.
I `m using Eclipse as developing environment and I started receiving following error, which doesn`t tell me anythnig:

HTTP Status 500 -
type Exception report

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
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)


root cause

java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:610)

(and so on)


So I guess the problem comes from the server I`m using (Tomcat 6.0). Previously it ran without a problem, and suddenly started giving this error. I`ve restarted it and nothing changes.


Any suggestions ?

Oh, I forgot to tell you, that the information in the input fields is successfully saved in the database in spite of this error.

fankoff 0 Newbie Poster

Hi JavaAddict,

thank you for the detailed answer!! I would kindly ask you to somehow specify this part though:

Instead of going to the according.jsp go to a servlet, do the insert there and then redirect to the inital page using the RequestDispatcher.

It sounds very plausible to me, but I wouldn't know how to actually accomplish it

I thought the according.jsp is the servlet itself? And how exactly do I redirect back to the HTML containing the form?


Let me show you a sample part of the HTML structure :

<form method="post" action = "insertArtist.jsp" >
 < input type="text" name="name" />
 < input type="text" name="surname" />
 < ... some other input information > 
 < input type="submit" name="submit_personal" value="forrward me!" />
</form>

<form method="post" action = "insert_contacts.jsp" >
  < input type="text" name="telephone" />
  < ..... />
  < input type="submit" name="submit_contacts value="save contacts" />

About my JSPs: since I`m using Eclipse as developing environment, when I choose "new JSP" it comes with the whole HTML-structure. So it looks like this

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<html>
<head> ... </head> 
<body> 
   <%
     [I]here my JSP-instructions[/I]
   %> 
</body> etc.

So yes, I`m absolutely new to all this, so please excuse me for the "lame" questions. I come from the "let`s make it look good" side of the things and only now I try to dig deeper in the code-part.
It is very annoying to explain stuff to novice, I know....

Thank you in advance

fankoff 0 Newbie Poster

Hi guys,

I need an advice on a html-refreshing issue

I have one html document containing three different forms with three submit buttons for each form.
The first form has some input fields for personal information (name,surname, age etc). When the user fills in the fields, presses the submit button, all the information is send to the DB and saved there. The problem is, when the user presses the submit button, the according .jsp for the form is activated and I loose my html site (it gets redirected to a blank white page).
How can I make it not jump to the blank page, but to stay on the same HTML site, execute the JSP and give a short feedback like "your data has been saved". Then the user can go on to fill the next form - the contact details.

There, the DB should recognize that this is the same user and save his contacts accordingly with the same userID. Here a second question:How do I manage this with seassions or with passing variables?


Any any help is much appreciated.

thanks!

fankoff 0 Newbie Poster

Hallo guys,

I want to first start by saying, that I`m fully aware the question I`m about to ask, has certainly already been posted some thousand times. I`ve looked through some of the posts, but non of them was quite like my case (or I just didn`t stumbled upon any) .

Maybe I should first try to explain what my difficulty is:
I`m working on a project for my studies. I want to build a small platform, where people can create accounts and put in what there abilities are. Possible employers then look for appropriate features etc.

I have one HTML document so far, which contains 3 forms,put one under the other:
1. First form is User personal Information (name, age etc) submit button, that sends only that personal information to the DB.
2. In the second form beneath it, comes all the abilities information (area, skills, experience etc) submit button to send this info to DB
3.Third form - Contact section (telephone, e-mail,etc) + submit button for the DB

When the User first sends his personal info to the DB, an unique UserID-key is created. In order to put all the following information (abilities and contacts) to this one user, I need to extract this key from the DB and somehow globaly save it for the other forms to use it.

So my question:
How can I pass a variable from one JSP to another? / OR / How …