I'm developing a web page, in that page at bottom I have to upload a file. I have code for upload, but that is in JSP. How I can include that JSP in my HTML page?
index.jsp
<%# 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Upload Example in JSP and Servlet - Java web application</title>
</head>
<body>
<div>
<h3> Choose File to Upload in Server </h3>
<form action="UploadServlet" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="upload" />
</form>
</div>
</body>
</html>
You can include an html file in a jsp file but cannot include a jsp file in a html file because html files are not parsed on the server-side (so how will the server know to do the include?) and jsp are (assuming you are using a servlet-container).
Make the main file a JSP, put the snippet in an html file, then include in your DIV by using
<div>
<jsp:include page="snippet.html" />
</div>
Related
Okay, I'm new to JSP and I'm trying to create a simple form with button in a JSP file index.jsp and link it to bootstrap. I just can't figure out how to call the bootstrap files from JSP. Here is my JSP code:
<%# 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href=”Bootstrap/css/bootstrap.min.css” rel=”stylesheet” type=”text/css” />
<script type=”text/javascript” src=”Bootstrap/js/bootstrap.min.js”></script>
<title>Bootstrap Project</title>
</head>
<body>
<div class=”container”>
<form role=”form”>
<div class=”form-group”>
<label for=”exampleInputEmail1″>Email address</label>
<input type=”email” class=”form-control” id=”exampleInputEmail1″ placeholder=”Enter email”>
</div>
<div class=”form-group”>
<label for=”exampleInputPassword1″>Password</label>
<input type=”password” class=”form-control” id=”exampleInputPassword1″ placeholder=”Password”>
</div>
<div class=”form-group”>
<label for=”exampleInputFile”>File input</label>
<input type=”file” id=”exampleInputFile”>
<p class=”help-block”>Example block-level help text here.</p>
</div>
<div class=”checkbox”>
<label>
<input type=”checkbox”> Check me out
</label>
</div>
<button type=”submit” class=”btn btn-default”>Submit</button>
</form>
</div>
</body>
</html>
And here is my folder arrangement:
I'm using Eclipse IDE and Tomcat as the server. Where am I going wrong?
Thanks.
I am learning Jsp and working on a basic Jsp project which is using a HTML file in it.
When I run the HTML file, it gives page not found error and while running the Jsp, it does not load the form and button in it.
Kindly help me out.
Below are my HTML and Jsp files:
Index.html
<html>
<head><title>New</title></head>
<body>
<form action="myFirstJsp.jsp">
<input type="text" name="uname">
<input type="submit" name="submit">
</form>
</body>
</html>
myFirstJsp.jsp
<%#page import="java.util.Calendar"%>
<%# 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My First JSP</title>
</head>
<body>
<%String name= request.getParameter("uname");
out.println("Welcome " +name);%>
</body>
</html>
First check if your server is up & your app is well deployed on it. Check the request url being fired from the browser.
Also
It's a good practice to use jstl tag to provide urls in your application. It computes the context path averting 404 page not found errors due to incorrect urls.
<form action="<c:url value="/myFirstJsp.jsp">
Add the jstl library in your jsp
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"/>
In my website, I download a full webpage from another site, modify something and extract it as a string. Now, I want to display it as a part of my .jsp page, with scrolling bar.
How can I do that? It shows me error when I try to put another <html> tag.
Thanks for your help.
EDIT!!!
Here is my .jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Create Your XSLT Here</title>
</head>
<body>
<form action="../AdminServlet">
URL <input type="text" name="txtUrl" value="" /><br/>
Start Promotion <input type="text" name="txtStart" value="" /><br/>
Produt Name <input type="text" name="txtProductName" value="" /><br/>
<input type="submit" value="View" name="action" />
</form>
<c:if test="${not empty requestScope.website}">
<div>
${requestScope.website}
</div>
</c:if>
</body>
</html>
requestScope.website is a full html page as a string, return from server. When I run, everything in the requestScope.website (such as background image) apply to all my page. I want to limit it to a part of my page, just like using iframe.
I think u can use the <jsp:include ...>tag.
Put the whole source code into a jsp and use the tag to include to your page.
Something like
<jsp:include page="mypagepath/page.jsp"></jsp:include>
This is my HTML form :
<form action="supplierportal_home.jsp">
<select id="contract" name="contract">
<option selected="selected">Please Select</option>
<option value="open" >Open</option>
<option value="limited" >Limited</option>
</select>
<input type="text" name="cpv_code" placeholder="<%= cpvOrTenderNo %>">
<button type="submit">FIND <%= contractOrTender %></button>
</form>
And i am getting in JSP
String contract=request.getParameter("contract");
System.out.println("%%%"+contract);
String cpv_code=request.getParameter("cpv_code");
System.out.println("%%%"+cpv_code);
Here is the problem.Seems very nasty.
When I enter both the values then only parameters getting in jsp If I select only the contract from options then null is coming if i give cpv-code then the parameter is coming ...can any one please help to get out this ...
Why my select option values are depending on the other form element cpv-code value,please show some cause for this.
Thanks.
<button type="submit">FIND <%= contractOrTender %></button>
In this example whenever you will enter text in textbox then only contractOrTender
this value can be objtain from textbox.
But as you not entering any value in textbox and trying to access value from dropdown it will come 'null' only. as boz at this time <%= contractOrTender %> this value is null.
which an error in jsp page. thats why you not getting dropdown value even if you dont enter any value in textbox.
Solution
Try to set some default value to textbox. or
change your HTML code.
I have just tested the code and it seems to work fine. No value is depending on the other. Only suggestion is add method="POST" if you don't want the data to be sent over URL.
index.jsp:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index Page</title>
</head>
<body>
<form action="upload.jsp" method="POST">
<select id="contract" name="contract">
<option selected="selected">Please Select</option>
<option value="open" >Open</option>
<option value="limited" >Limited</option>
</select>
<input type="text" name="cpv_code" />
<button type="submit">FIND</button>
</form>
</body>
</html>
upload.jsp:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Upload JSP</title>
</head>
<body>
<%
String contract=request.getParameter("contract");
System.out.println("%%%"+contract);
String cpv_code=request.getParameter("cpv_code");
System.out.println("%%%"+cpv_code);
%>
</body>
</html>
I am tring to run function that get 2 variables one of them should get the value from textfield.
any advice?
<%#page import="root.SQLQuery"%>
<%# page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%# page import="root.SQLQuery"%>
<%
String emp_email = session.getAttribute("email").toString();
SQLQuery sql = new SQLQuery();
String link="";
%>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
<center>
<table width="900" height="900">
<iframe src="http://www.aol.com/av" width="900" height="900"></iframe>
<center>
<font color=red>your email is:<%=emp_email%>></font>
Copy the link here: <input type="text" name="videoLink" id="link">
<input type="submit" value="submit" onclick="<%sql.meetingUpdateVideoLink(emp_email, request.getParameter("videoLink").toString()); %>>">
</center>
</table>
</center>
I am tring to insert the fanction meetingUpdateVideoLink() two variables:
email - that easy I get from session.
Link - that is the tricky one I need to get it from the textfield name="videoLink"
Thanks,
Cfir