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>
Related
I have a problem with JSP Bean's scope - Request. I have a page Index.jsp with jsp bean 'message', its scope is Request and a page result.jsp. When I send request to result.jsp from Index.jsp. My bean 'message' should keep its value but it doesn't now.
I tried with scope Session and my bean worked well. I search all questions about this problem but no answer can meet my question.
Here is my code:
file Index.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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">
</head>
<body>
<%
String name = request.getParameter("name") == null ? "" :
request.getParameter("name");
int age = ( request.getParameter("age") == null ||
request.getParameter("age") == "") ? 0 :
Integer.parseInt(request.getParameter("age"));
%>
<h1>Nice to meet you</h1>
<form method="post" action="View/result.jsp">
<jsp:useBean id="message" class="com.java.Message" scope="request"/>
<jsp:setProperty name="message" property="message" value="Hello world!"/>
<label>Name: </label> <br>
<input type="text" name="name" placeholder = "Phan Dinh The"/> <br>
<label>Age: </label> <br>
<input type="number" name="age" placeholder = "25"/> <br>
<input type="checkbox" name="title"/> Senior <br>
<input type="radio" name="language" value="c#"/> C# <br>
<input type="radio" name="language" value="java"/> Java <br>
<br><br>
<jsp:include page="View/date.jsp" flush="true"/>
<input type="submit" value="submit"/>
<br><br>
</form>
<br><br>
</body>
</html>
file result.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.java.Message"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!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>Insert title here</title>
</head>
<body>
<jsp:useBean id="message" class="com.java.Message" scope="request"/>
<jsp:getProperty name="message" property="message"/>
</body>
</html>
my class Message
package com.java;
public class Message {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String content) {
this.message = content;
}
}
I use Tomcat 8.0.23, Jsp version 2.3, Servlet API 3.1
When you use
<jsp:setProperty name="message" property="message" value="Hello world!"/>
in the index.jsp file, that property is scoped to the request of the index.jsp page. once the index jsp page returns to the client, that request is done. When you submit the form, a new request is created, and that is used for the result page generation. Thus when you are in the result.jsp code, there is no request scoped parameter named 'message'.
You could always put the message in an
<input type="hidden" name="message">Hello World</input>
field of the form, and retrieve it in the results.jsp that way.
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>
Here is my code that Search Result From Google.somewhere is written that i have to set 'start' to '0' but as i'm a very Newbee in java i really don't khow what should i do.so any help will appreciate.
<%# 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">
<%#page import="com.demo.GoogleSearch"%>
<%#page import="java.util.List"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%#include file="SearchGoogle.jsp" %>
<%
String word=request.getParameter("searchWord");
List<String>urls=GoogleSearch.searchWord(word);
%>
<table>
<%
int b = urls.size();
for(int i=0;i<b;i++){
//if (i < b)
%>
<tr><td><%=urls.get(i) %></td></tr>
<%} %>
</table>
</body>
</html>
And Here is the page for Sesrch:
<%# 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>Insert title here</title>
</head>
<body>
<form action="SearchResults.jsp">
<table>
<tr><td>
Enter Search Word:</td><td>
<input type="text" name="searchWord"/></td></tr>
<tr><td colspan="2">
<input type="submit" value="search">
</td></tr>
</table>
</form>
</body>
</html>
I think 4 search results is Google's limit on results when calling it through their API, unless you want to pay for the searches. In uni I had to make a project which needed to get results from a search engine, we used GigaBlast since it has a nice API and a much larger limit of results returned per search (50 if I recall right).
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
Hy!
I have a jsp site called konto (engl. account)
At the end i have a button that should invalidate the current session by clicking and redirect back to the loginpage but that doesn't work.
Code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="konto" scope="session" class="at.korn.web.Konto"></jsp:useBean>
<% if (session.getAttribute("user")== null)
{
%>
<jsp:forward page="index.jsp"></jsp:forward>
<% }
if (request.getParameter("logout")!= null)
{
session.invalidate();
%>
<jsp:forward page="index.jsp"></jsp:forward>
<% } %>
<% konto.holeKontostand(String.valueOf( session.getAttribute("user")));%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Konto</title>
</head>
<body>
<h1>Kontoübersicht</h1>
<p>Herzlich Willkommen <% out.print(session.getAttribute("user"));%> </p>
<p>Ihr Kontostand beträgt: ${konto.ktostand} </p>
<input type="submit" value="Logout" name="logout" />
<br>
</body>
</html>
The Error should be in that file.
Please help!
You need to put the button in a <form> in order to get it to work.
<form>
<input type="submit" value="Logout" name="logout" />
</form>
That said, mingling model, view and controller in a single JSP (view) isn't the best practice.