When a file is selected it must set the fileName with path to a textField with path="inputFileName". I tried to below code which is not working as setFileName is not called either onClick nor onSelect.
Any pointers how this can be done will be great help to me.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%!
public void setFileName(){
System.out.println("In SetFile Name for InputFile");
}
%>
<html>
<body>
File Convertor
<PRE>
<f:form method="PUT" commandName="file2" >
Input File <f:input path="inputFileName"/><input type="file" name="ChooseMyFile" value="A" onclick="setFileName()" onselect="setFileName()"/>
Output File <f:input path="outputFileName"/>
</f:form>
</PRE>
</body>
</html>
Related
I'm having a problem with displaying a string in jsp view. A a web framework I'm using Spring MVC.
The view (return.jsp) is like that:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>FredomWings</title>
</head>
<body>
<b>Result -></b>
<p>${currentValue}</p>
</body>
</html>
The controller looks like that:
#RequestMapping(value="balance")
public String getBalance(Model model) {
model.addAttribute("currentValue","alalal");
return "return";
}
What is the reason for which in the jsp page only Result -> without any value is displayed?
I am trying to bind a list to drop down in JSP. Below is my controller and JSP.
Controller:
#Controller
public class WeatherServiceController {
#Value("#{'${countryList}'.split(',')}")
private List<String> countries;
#ModelAttribute("CountriesList")
private List<String> getCountries(){
System.out.println(countries.size());
return countries;
}
#RequestMapping(value = "/getweather", method=RequestMethod.GET)
public ModelAndView getWeather(){
Place p = new Place();
ModelAndView mav = new ModelAndView();
mav.addObject("place",p);
mav.setViewName("home");
return mav;
}
}
JSP:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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>Weather Service Client - Home</title>
</head>
<body>
<h2>Welcome to Weather Service</h2>
<form:form modelAttribute="place" action="getWeather">
<table>
<tr>
<td><form:label path="country">Country:</form:label></td>
<td>
<form:select path="country" items="${CountriesList}">
</form:select>
</td>
</tr>
</table>
</form:form>
</body>
</html>
But I am getting error like "Type [java.lang.String] is not valid for option items". Country list is not coming in jsp page. Please help me what I did wrong here.
It is working now.
I have added below line in jsp page.
<%# page isELIgnored="false" %>
I thought by default "isELIgnored" is set to false, so I haven't included earlier. After including this page is binding list result.
I am doing on a MVC project using netbean IDE and I have a problem with displaying my objects on table
This is my jsp page
<%#page import="java.util.List"%>
<%#page import="java.util.ArrayList"%>
<%#page import="model.Clothes"%>
<%#page import="org.hibernate.Session"%>
<%#page import="cfg.HibernateUtil"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#taglib prefix="display" uri="http://displaytag.sf.net" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Clothes</title>
</head>
<body>
<div style="margin-left: 10%; ">
<%
Session session1 = HibernateUtil.getSessionFactory().getCurrentSession();
List<Clothes> clothes = new ArrayList<Clothes>();
session1.beginTransaction();
clothes = session1.createQuery("from Clothes").list();
session1.getTransaction();
System.out.println(clothes.size() + "aaaaaaaaa");
session1.close();
request.setAttribute("results", clothes);
%>
<display:table name="results" pagesize="10"/>
</div>
<jsp:include page="/index.htm" flush="true"/>
</body>
And the browser display an exception at line contains 'display' tag like this:"org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/clothes.jsp" Where did I do wrong, please help me, I am newbie in java web.
p/s: I add libs in my project, they are: displaytag-1.2, displaytag-export-poi-1.2, displaytag-portlet-1.2 and commons-lang-2.6.
I followed #JB Nizet instruction and it worked, just use the libs exactly the same that listed in this link: http://www.displaytag.org/1.2/displaytag/dependencies.html
However, in some PC, when using org.slf4j, your project can not work properly, just remove them from the project, it is OK!
My get ParameterValues method is not working, i am trying to retrieve the values from JSP page to MVC controller below is the code snipet for MVC page
#RequestMapping(value="/searchQuery", method=RequestMethod.POST)
public ModelAndView submitForm(HttpServletRequest request, ModelAndView model) {
System.out.println("Called submitfform method");
String[] listBox1 = request.getParameterValues("selectedright");
String[] listBox2 = request.getParameterValues("selectedright2");
String to_date=request.getParameter("date1");
String from_date=request.getParameter("date2");
System.out.println(listBox1);
System.out.println(listBox2);
List<ItemMaster> lists=itemDao.fetchRecords(listBox1,listBox2,to_date,from_date);
model.addObject("queryResult",lists);
model.setViewName("results");
System.out.println(lists.size());
// m.addAttribute("message", "Successfully Requested person: " + adhoc.toString());
return model;
}
Below is the snipet of JSP page from where I am trying to retrieve whole JSP page is to big to paste over here.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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>ADHOC Report</title>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
<! -- My Functions >
</script>
</head>
<BODY id="body" bgcolor="#f5f5f5" onload="preventBack();">
<!-- <onpageshow="if(event.persisted) preventBack();"> -->
<form:form action="searchQuery" method="post">
<table width="100%" height="30%" border="1" align="center"
cellpadding="4" style="text-align: center; background-color: white">
</table>
<br>
I am trying to create a form. Where the user need to select a file path.
This can be done in html as
<input type="file" name="inputFileName"/>
If we use html then I don't know how to map that value to "fileObject" class.
So how should I do this with the following code throwing a warning "Undefined attribute name type "
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<f:form method="PUT" commandName="fileObject" >
<f:input type="file" path="inputFileName"/>
</f:form>
</body>
</html>
Exception:
org.apache.jasper.JasperException: /WEB-INF/jsp/Main.jsp(9,0) Attribute type invalid for tag input according to TLD
f:input does not have attribute type as you can find it in docs