Results 1 to 20 of 24
Thread: how to call jsp from html
- 01-25-2012, 09:27 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
how to call jsp from html
hi all,
i have jsp file and i want to call that by html file so for that i used mapping in web.xml file but i am not getting how to call that jsp from html file
my html file name is :- test1.html
Java Code:<html> <head> </head> </body> <a href="firstjsp"> -- test here is first jsp --</a> </body> </html>
my jsp file name is :- test.jsp
and my web.xml file is
please suggested me ...Java Code:<servlet> <servlet-name>firstjsp</servlet-name> <jsp-file>/test.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>firstjsp</servlet-name> <url-pattern>/firstjsp</url-pattern> </servlet-mapping>
- 01-26-2012, 09:38 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: how to call jsp from html
Why are you mapping your jsp?
Just reference it directly?
- 01-26-2012, 11:22 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: how to call jsp from html
Spammer reported.
- 01-26-2012, 11:39 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: how to call jsp from html
It's a good thing (tm) that the rotating knives machine has a solid transparent lid on top of it; while it's fun to see the fear in the eyes of the spammer just before he's sliced up to small pieces, I guess the sound of him, screaming in terror, would be less pleasant.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-26-2012, 11:46 AM #5
- 01-26-2012, 12:10 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: how to call jsp from html
No need to worry; no violence was used: I lured the spammer into the machine telling him there probably was money in there; he voluntarily climbed into the machine, I closed the lid and switched on the machine, that's all; and now he is just a pile of slimey remnants and bloody pulp. ;-)
kind regards,
Jos
ps. I'll clean up the machine later.When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-26-2012, 12:16 PM #7
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
Re: how to call jsp from html
hi tolls
thanks for reply ...
but i want to pass some parameter to JSP page
i am trying to mapping JSP in web.xml because i do not want to expose jsp file name outside.
thanks in advance.
- 01-26-2012, 12:30 PM #8
- 01-26-2012, 12:49 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 01-26-2012, 01:32 PM #10
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
Re: how to call jsp from html
thanks tolls
got it
i have one more question ..
form my servlet i am inserting some data in mysql databse and form JSP page i am retrieving those data. but when i refresh my JSP page that time last row of database automatic make duplication.
thanks
- 01-26-2012, 01:39 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: how to call jsp from html
Without seeing code (and I hope you aren't actually doing the retrieve in the JSP) I couldn't say.
- 01-26-2012, 01:50 PM #12
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
Re: how to call jsp from html
my servlet code
my jsp codeJava Code:String name = request.getParameter("username"); String pass = request.getParameter("password"); try{ conn = db.getConnection("hii"); pstmt = conn.prepareStatement("insert into login_table (user,pass) VALUES(?,?)"); pstmt.setString( 1, user); pstmt.setString( 2, pass); pstmt.executeUpdate(); out.println("done"); pstmt.close(); conn.close(); RequestDispatcher view = request.getRequestDispatcher("/jsp/showall.jsp"); view.forward(request,response); }
insert complete then control goes to JSP and every time i refresh JSP page that time last entry which i entered entry again and again and show with all data.Java Code:<% Connection conn; ResultSet rs; Statement statement; DB_Connection db =new DB_Connection(); try{ conn = db.getConnection(); statement= conn.createStatement(); rs = statement.executeQuery("Select * from login_table"); while(rs.next()){ %> <table border="1" > <tr> <td width="100"><%=rs.getString(1)%></td> <td width="100"><%=rs.getString(2)%></td> </tr> </table> <% } statement.close(); conn.close(); }
- 01-26-2012, 01:54 PM #13
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
Re: how to call jsp from html
like in database :-
id name pass
1 abc abc
when it refresh JSP page
id name pass
1 abc abc
2 abc abc
again refresh
1 abc abc
2 abc abc
3 abc abc
- 01-26-2012, 02:52 PM #14
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
Re: how to call jsp from html
my problem has been solved .. i used "sendRedirect" instead of forward.
if you have any suggestion then i will like to welcome your suggestion.
thanks tolls.
- 01-26-2012, 03:03 PM #15
Re: how to call jsp from html
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-26-2012, 03:34 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: how to call jsp from html
That would sort it, as the refresh was doing a resend of the data you sent (ie going to the insert servlet).
One way to avoid the duplications is to improve your primary key possibly, then catch the duplicate key exception?
JSPs are intended for displaying data, not processing it.
It's bad practice to have raw Java code in there and, to be honest, I don't like the idea of data-fetching tags either.
For raw code, it's a swine to debug and is also harder to read since it is surrounded by tags and all the other HTML/JSP cruft you get.
FOr data-fetching, well...it's doing it in the wrong place.
A web-app should consist of a few layers.
Your Servlet (or equivalent in frameworks like Struts and Spring) that controls the flow of data. Takes the request and sends the relevant bits to your
Business Layer which crunches the data (insert into databases, makes calls to web services, fetches data from here there and everywhere). It should be possible to lift this layer out from your webapp. It should have no reliance on it. The data that's returned from this layer is the forwarded (by the servlet) to
The View Layer. This is your JSP. It takes the data in the request and displays it.
- 01-26-2012, 03:45 PM #17
Member
- Join Date
- Oct 2010
- Posts
- 42
- Rep Power
- 0
Re: how to call jsp from html
you mean to say html form send the data and servlet and servlet will pass this data to plain old java class and that class will insert data and query data. in case i want to retrieve bulk data which i want to show using jsp , so how can i implement this idea? by retrieve all data in arraylist and return this arraylist to servlet and then servlet will return this arraylist to jsp ? is that right thing ?
- 01-26-2012, 03:58 PM #18
Re: how to call jsp from html
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-26-2012, 04:19 PM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: how to call jsp from html
Pretty much. One advantage is that it really forces you to avoid trying to splurge large amounts of data onto a single page.
Of course things like Ajax change the flow a bit, but then, instead of passing the stuff to a JSP, you're creating some JSON string and sending that to some Javascript to process.
There are two things to always remember about servlets.
1. Never store anything in them (except possibly local constants).
2. Get out of them as quickly as possible.
- 01-26-2012, 04:28 PM #20
Re: how to call jsp from html
Thanks, I'll keep that in mind. I don't mean to hijack the OP's post, but the concept of where a servlet begins and ends is one of the last things I think I need to get into my brain before I begin to really "understand" the web stuff I've been working on in my spare time. Maybe my confusion comes from my (probably incorrect) approach with tomcat and webapps- I'm not sure where a webapp should begin and end either, so the whole site (including login, uploading, viewing, etc) is mashed into one big webapp. So the code that probably belongs in a separate servlet is also jammed into there with no clear line of what a servlet "is".
At least I did create a hibernate API, so I don't have a ton of sql embedded directly in my jsp code... at least, not anymore.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
How to call javascript when the html is rendered from PERL
By camaross in forum New To JavaReplies: 3Last Post: 05-16-2011, 01:50 AM -
call by value and call by reference in java
By sandeepsai39 in forum New To JavaReplies: 7Last Post: 08-12-2010, 11:03 AM -
How can I include a html file in html textarea?
By surya_dks in forum New To JavaReplies: 2Last Post: 10-04-2008, 07:20 AM -
call executable jar from html/jsp
By Zahari in forum JavaServer Pages (JSP) and JSTLReplies: 6Last Post: 12-06-2007, 12:00 AM -
how to call a JAR FILE from HTML
By leonard in forum Java AppletsReplies: 1Last Post: 08-05-2007, 06:06 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Jos, be careful. They may close the site due to violence.

Bookmarks