This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How To call .html form from JSP  RSS feed

 
Rahul B. Shah
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,
I Am New To JSP & Servlets & I Have Created Simple Login Form Design In HTML & Then Called login.jsp where
it checks whether login is successfull or not & its working & now what I want do is call different .html form after
login is successfull,so i need help.

logindesign.html :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<form action="login.jsp" method="post">
<h1 align="center">Please Login</h1>
<table>
<tr>
<td>Username :</td><td> <input type="text" name="login" size=15 /></td>
</tr>
<tr>
<td>Password :</td><td> <input type="text" name="password" size=15 /></td>
</tr>
</table>
<input type="submit" value="LOGIN">
</form>
</body>
</html>

login.jp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
String uername = request.getParameter("login");
String passwd = request.getParameter("password");
if(uername.equals("admin") && passwd.equals("chief"))
{
session.setAttribute("authorized","yes");
out.println("Login Done");//I want to call different html form after login is successfull.

}
else
{
session.setAttribute("authorized","no");
out.println("Login Not Done");
}
%>

Thank-You
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul B. Shah wrote:I Am New To JSP & Servlets & I Have Created Simple Login Form Design In HTML & Then Called login.jsp ...

As a newcomer to JSP and servlets it is important to learn the correct concepts and to avoid establishing bad practices from the outset. The way you are doing this is wrong. You should never, ever submit to a JSP, and you should never put Java code in JSP with scriptlets. That's a poor practice from about 10 years ago that has been thoroughly discredited.

Rather, you should submit to a servlet which will process the data and then forward or redirect to the next view to be displayed.

Perhaps this article this article will be helpful in outlining proper web application structure.
 
Shashank Ag
Ranch Hand
Posts: 88
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear is right you should listen to him.
However, the answer to your question is simple. You can never submit a form data to html file. Hence, if its a html you can just put anchor tag (<a> </a>) to make links.
Otherwise you can also you servlet request dispatcher to include html content in response.
 
murali ganesh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rahul,
same as everyone my advice is to go for servlets. the ans to your question is quite simple you can go for redirect function. Here is a sample
<%
String redirectURL = "http://localhost:8080/ur file location/";
response.sendRedirect(redirectURL);
%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
murali ganesh wrote:Here is a sample...

It's long past the time that Java code should be place din JSPs. This is 2011 not 2001.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!