|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
java and jsp..please help .
my application is a web based library and i'm new to this field.
i created html files and jsp files and java files corresponding to the system .i want to know how should i test it using tomcat.my database is mysql . |
|
#2
|
||||
|
||||
|
I would install tomcat on my local machine and copy your files to tomcat's webapps directory.
You can download tomcat here. Here's an article on installing tomcat on windows.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
thanks a lot .the article helped me a lot.
for my application i have created html pages as interfaces , and jsp(actually a very few yet) and java beans. i created my application folder libraryapp under webapps and created 3 subfolders called conf,WEBINF and src. and it doesnt show my page. is that correct? |
|
#4
|
||||
|
||||
|
Under which folder are you placing the HTML and JSP files?
|
|
#5
|
|||
|
|||
|
under webapps i created 3 folders,WEB-INF,src and conf.
i placed html and jsp in src folder. and web.xml in WEB-INF. |
|
#6
|
||||
|
||||
|
You might want to create a single folder for your project.
TOMCAT_HOME/webapps/library_project/ try sticking your files in there. |
|
#7
|
|||
|
|||
|
what is that main.conf file in conf folder? .i use intellij idea asthe ide.
how to deploy and do the war file? |
|
#8
|
|||
|
|||
|
html and java
my application is a web based library system.
and i have to implement search facility of books. i want to know how to get the resultset of a search to a web page's table(html table) i.e, when search is done through excecuteQuery method of stmt object, how to send the result set to a table to show the output.i mean how to get the resultset object looped in to a table. thanks in advance |
|
#9
|
||||
|
||||
|
This is a part of my JSP where I show the details of every found film in a list.
Code:
<DIV id=scroll1 style="BORDER:2px; OVERFLOW: auto; position: absolute; width: 700px; height: 250px; visibility: visible; left: 157px; top: 317px;">
<table width="600" border="0" align="center" id="lijst">
<%
for (Iterator i = filmLijst.iterator(); i.hasNext(); )
{
Film film = (Film) i.next();
%>
<tr>
<td width="80"><input name="detail" type="submit" id="detail" value="<%=film.getFilmnummer()%>"></td>
<td width="274"><%=film.getTitel()%> </td>
<td width="113"><%=film.getJaaruitgave()%></td>
<td width="115"><%=film.getGenre()%></td>
</tr>
<% } %>
</table>
</DIV>
In the declaration of my JSP, I've put : Code:
<%@ page import = "java.util.Iterator" %> <%@ page import = "org.gertcuppens.cluif.Film" %> <jsp:useBean id="filmLijst" class="java.util.ArrayList" scope="session"/> You need iterator to go through the ArrayList called filmLijst. Each of these objects you find has to be cast to an object of the class Film. Where did I make this filmLijst ? that was in the filmDao (DAO stands for Data Access Object, a java class which contains the SQL instructions) Code:
public ArrayList zoekFilmOpLetter(String _letter)
throws Melding
{
ArrayList filmLijst = new ArrayList();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
StringBuffer zoekString = new StringBuffer();
zoekString.append("select * from film ");
zoekString.append("where titel like '" + _letter + "%'");
System.out.println("zoekstring heeft de waarde " + zoekString);
con = getDatabaseConnection();
ps = con.prepareStatement(zoekString.toString());
rs = ps.executeQuery();
if (rs == null)
{
ps.close();
con.close();
System.out.println("geen film gevonden");
}
else
{
while (rs.next() )
{
Film film = new Film (rs, "lijst");
System.out.println("gevonden film is " + film.getTitel());
filmLijst.add(film);
} /* while rs.next() */
rs.close();
ps.close();
con.close();
} /* else : rs != null */
} catch (SQLException sqlEx)
{
Melding melding = new Melding(sqlEx);
throw melding;
}
catch (Melding melding)
{
throw melding;
}
return filmLijst;
}
The DAO is created and then used in the servlet. Code:
private String behandelAlfabet (HttpServletRequest _request)
{
Logger gcoLogger = Logger.getLogger("gco.log");
String radioLetter = _request.getParameter("radioLetter");
System.out.println("gcoController -- radioLetter is " + radioLetter);
gcoLogger.debug("gcoController -- radioLetter is " + radioLetter);
if (_request.getParameter("selecteren") != null)
{
System.out.println("button is selecteren");
gcoLogger.debug("button is selecteren");
return SELECTIE_PAGINA;
}
else if (_request.getParameter("zoeken") != null)
{
System.out.println("button is zoeken");
gcoLogger.debug("button is zoeken");
HttpSession sessie = _request.getSession(true);
// if (sessie == null) sessie = _request.getSession(true);
FilmDao filmDao = new FilmDao();
ArrayList filmLijst = new ArrayList();
try {
filmLijst = filmDao.zoekFilmOpLetter(radioLetter);
Melding melding = new Melding("selectie op films beginnend met " + radioLetter);
_request.setAttribute("melding",melding);
} catch (Melding melding)
{
// Melding melding = new Melding(exc);
//HttpSession sessie = _request.getSession(false);
/* plaats de melding in request; als je melding
* in sessie plaatst, blijft de foutmelding terugkomen
* ook al is ze niet meer van toepassing
*/
_request.setAttribute("melding", melding);
System.out.println("gcoController -- melding klaargezet in behandelLetter() ");
System.out.println("melding boodschap is " + melding.getBoodschap());
System.out.println("melding SQL is" + melding.getSQLMelding());
}
sessie.setAttribute("filmLijst", filmLijst);
return FILMLIJST_PAGINA;
} /* selecteren geklikt */
else
{
System.out.println("behandelalfabet : onvoorzien geval");
gcoLogger.debug("behandelalfabet : onvoorzien geval ");
return ALFABET_PAGINA;
}
} /* behandelAlfabet () */
Mind the line Code:
sessie.setAttribute("filmLijst", filmLijst);
With this I put the Arraylist called filmLijst inside the session. And with this, the JSP can retrieve the found values and show them. All you have to do, is provide the next line in the JSP. Code:
<jsp:useBean id="filmLijst" class="java.util.ArrayList" scope="session"/> |
|
#10
|
|||
|
|||
|
hi,
thank you so much. your note is really good i learnt a lot from it. |
|
#11
|
|||
|
|||
|
jsp/java and tomcat
hi,
how to integrate jsp pages and java files and html files created in to a web based application. i mean making the war file. |
|
#12
|
||||
|
||||
|
making a war file
I have never made a war file myself; the server I deploy my web apps, does not support this.
But I managed to find the following information with google : Quote:
These links might be useful : configuring web apps creating a war file |
|
#13
|
|||
|
|||
|
hi,
when my application (web based library) is tested it doesnt write data to the database. i created database using mysql. when data is entered through webpage it doesnt write to the db. why? |
|
#14
|
||||
|
||||
|
try-catch block
Whenever you're executing SQL statements, you should be prepared for errors with a try catch block. Did you write this block ? Are there any SQLerrors you catch ?
ANd give us a piece of your code where you think it goes wrong. |
|
#15
|
|||
|
|||
|
cannot connect to mysql DB
the code goes here of the coonection test..
Code:
class conTest {
public static ConnectionPool pooler = new ConnectionPool();
public static Connection con = null;
public void init() {
try {
if (pooler.getDriver() == null) {
pooler.setDriver("org.gjt.mm.mysql.Driver");
pooler.setURL ("jdbc:mysql://localhost/mygreatDB");
pooler.setUsername("root");
pooler.setPassword("password");
pooler.setSize(5);
pooler.initializePool();
}
con = pooler.getConnection();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
public static void main(String ar[]) {
conTest ct = new conTest();
..............
and with this i cant connect with the DB.. what is wrong here ..please point it.. |
|
#16
|
||||
|
||||
|
What is the error you are getting?
in the future, try wrapping your code fragments in [code][/code] tags when pasting to the forum. |