Search Results

Search found 3678 results on 148 pages for 'jsf jsp el'.

Page 43/148 | < Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >

  • why cookie.getMaxAge() = -1?

    - by wavelet
    i have a test like this : cookie.jsp: <html> <head> </head> <body> <% String cookieName="SNS"; Cookie cookie=new Cookie(cookieName, "maxAgeTest"); cookie.setMaxAge(60*60); response.addCookie(cookie); %> </body> </html> and read.jsp is : <html> <head> </head> <body> <table border=1> <tr><td>Name</td><td>value</td></tr> <% Cookie cookies[]=request.getCookies(); Cookie sCookie=null; String svalue=null; String sname=null; int sage ; for(int i=0;i<cookies.length;i++) { sCookie=cookies[i]; svalue=sCookie.getValue(); sname=sCookie.getName(); sage=sCookie.getMaxAge(); %> <tr><td><%=sname%></td><td><%=svalue%></td><td><%=sage%></td></tr> <% } %> </table> </body> </html> but the result is : Name value maxAge JSESSIONID DB3561A47B37FCA8CA25EA04B80A26C7 -1 SNS maxAgeTest -1 why the maxAge is -1 ? and t test IE8,Chrome5,Safari ,the result same

    Read the article

  • passing data from a servlet to javascript code in an Ajax application ?

    - by A.S al-shammari
    I have a simple jsp/servlet application and I want to add AJAX feature to this app. I use JQuery , but it doesn't matter what javascript framework I use. This is my code: <script type="text/javascript"> function callbackFunction(data){ $('#content').html(data); } $('document').ready(function(){ $('#x').click(function() { $.post('/ajax_2/servlet',callbackFunction) }); }); </script> <body> <a href="#" id="x">Increase it</a> <div id="content"></div> </body> </html> Servlet HttpSession session = request.getSession(); Integer myInteger = (Integer)session.getAttribute("myInteger"); if(myInteger == null) myInteger = new Integer(0); else myInteger = new Integer(myInteger+1); session.setAttribute("myInteger", myInteger); response.getWriter().println(myInteger); The Question: I use out.print to transfer data from a servlet to javascript code (ajax code) , but If I have a complex structure such as Vector of Object or something like this , what is the best way to transfer the data? what about an XML file , JSON ? Is there any special jsp/servlets library to transfer data from a servlet to ajax application ? How can I parse this data in callbackFunction ?

    Read the article

  • genStrAsCharArray optimisation benefits

    - by Rich
    Hi I am looking into the options available to me for optimising the performance of JBoss 5.1.0. One of the options I am looking at is setting genStrAsCharArray to true in <JBOSS_HOME>/server/<PROFILE>/deployers/jbossweb.deployer/web.xml. This affects the generation of .java code from .JSPs. The comment describes this flag as: Should text strings be generated as char arrays, to improve performance in some cases? I have a few questions about this. Is this the generation of Strings in the dynamic parts of the JSP page (ie each time the page is called) or is it the generation of Strings in the static parts (ie when the .java is built from the JSP)? "in some cases" - which cases are these? What are the situations where the performance is worse? Does this speed up the generation of the .java, the compilation of the .class or the execution of the .class? At a more technical level (and the answer to this will probably depend on the answer to part 1), why can the use of char arrays improve performance? Thanks in advance Rich

    Read the article

  • Java: Tracking a user login session - Session EJBs vs HTTPSession

    - by bguiz
    If I want to keep track of a conversational state with each client using my web application, which is the better alternative - a Session Bean or a HTTP Session - to use? Using HTTP Session: //request is a variable of the class javax.servlet.http.HttpServletRequest //UserState is a POJO HttpSession session = request.getSession(true); UserState state = (UserState)(session.getAttribute("UserState")); if (state == null) { //create default value .. } String uid = state.getUID(); //now do things with the user id Using Session EJB: In the implementation of ServletContextListener registered as a Web Application Listener in WEB-INF/web.xml: //UserState NOT a POJO this this time, it is //the interface of the UserStateBean Stateful Session EJB @EJB private UserState userStateBean; public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); servletContext.setAttribute("UserState", userStateBean); ... In a JSP: public void jspInit() { UserState state = (UserState)(getServletContext().getAttribute("UserState")); ... } Elsewhere in the body of the same JSP: String uid = state.getUID(); //now do things with the user id It seems to me that the they are almost the same, with the main difference being that the UserState instance is being transported in the HttpRequest.HttpSession in the former, and in a ServletContext in the case of the latter. Which of the two methods is more robust, and why?

    Read the article

  • java web templates across multiple WAR files

    - by Casey
    I have a multi WAR web application that was designed badly. There is a single WAR that is responsible for handling some authorization against a database and defines a standard web page using a jsp taglib. The main WAR basically checks the privileges of the user and than based on that, displays links to the context path of the other deployed WARS. Each of the other deployed WARs includes this custom tag lib. I am working on redesigning this application, and one of the nice things that I want to retain is that we have other project teams that have developed these WAR modules that "plug into" our current system to take advantage of other things we have to offer. I am not entirely sure how to handle the page templates though. I need a templating system that would be easy enough to use across multiple wars (I was thinking of jsp fragments??). I really only need to define a consistent header and main navigation section. Whatever else is displayed on the page is up to the individual web project. Any suggestions? I hope that this is clear, if not I can elaborate more.

    Read the article

  • return ArrayList from spring controller for ajax call and render in second dropdown

    - by user1708125
    I've a spring bean with 3 Maps all of which are to be populated incrementally. First map is an item category list, second map is a product list and third map is a hobby for item type list All the maps are mapped to and on the JSP. When the page is loaded only the first map is populated on the onchange event of first map, I need to populate the second map in the bean and similarly on the onchange event of second map, I need to populate the third map in the bean. Is there a way to do this using Ajax?? I need some code samples to how to render JSON response in second and third dropdown. Clarification: @Donal: I have a simple JSP page with 3 dropdowns corresponding to 3 maps stored in my commandBean. So when the page loads for the first time only the first map and hence the first dropdown is populated. Now whenever the user selects anything out of the first dropdown, I need to send the same commandbean back with the values of the first dropdown and get the values for the second map and hence the second dropdown and so forth for the 3rd dropdown as well. For each dropdown I 've got 3 maps and 3 variables for storing the selected values. Now I want to understand if this is possible using Ajax. I hope this clarifies whatever you need to know. Thanx

    Read the article

  • CSS file in a Spring WAR returns a 404

    - by Rachel G.
    I have a J2EE application that I am building with Spring and Maven. It has the usual project structure. Here is a bit of the hierarchy. MyApplication src main webapp WEB-INF layout header.jsp styles main.css I want to include that CSS file in my JSP. I have the following tag in place. <c:url var="styleSheetUrl" value="/styles/main.css" /> <link rel="stylesheet" href="${styleSheetUrl}"> When I deploy the application, the CSS page isn't being located. When I view the page source, the href is /MyApplication/styles/main.css. Looking inside the WAR, there is a /styles/main.css. However, I get a 404 when I try to access the CSS file directly in the browser. I discovered that the reason for the issue was the Dispatcher Servlet mapping. The mapping looks as follows. <servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> I imagine the Dispatcher Servlet doesn't know how to handle the CSS request. What is the best way to handle this issue? I would rather not have to change all of my request mappings.

    Read the article

  • html/js: Refresh 'Select' options

    - by framara
    Hi, There's a class 'Car' with brand and model as properties. I have a list of items of this class List<Car> myCars. I need to represent in a JSP website 2 ComboBox, one for brand and another for model, that when you select the brand, in the model list only appear the ones from that brand. I don't know how to do this in a dynamic way. Any suggestion where to start? Thanks Update Ok, what I do now is send in the request a list with all the brand names, and a list of the items. The JSP code is like: <select name="manufacturer" id="id_manufacturer" onchange="return getManufacturer();"> <option value=""></option> <c:forEach items="${manufacturers}" var="man"> <option value="${man}" >${man}</option> </c:forEach> </select> <select name="model" id="id_model"> <c:forEach items="${mycars}" var="car"> <c:if test="${car.manufacturer eq man_selected}"> <option value="${car.id}">${car.model}</option> </c:if> </c:forEach> </select> <script> function getManufacturer() { man_selected = document.getElementById('id_manufacturer').value; } </script> How do I do to refresh the 'model' select options according to the selected 'man_selected' ?

    Read the article

  • jquery is getting the old values from database

    - by sansknwoledge
    hi in my jsp page i am a having a jquery area which pass the values to a servlet which returns an output of dropdownlist . then the jsp file do some updation so certain values which are in the dropdownlist should not be there while repopulating. but it is not happening. my jquery code is $("#cbocode").change(function(){ var cdid=$("#cbocode option:selected"); $.get("trnDC?caseNo=20&cdid="+cdid.text(),function(data){ $("#divinstrument").html(data); }) and the servlet code is case 20:{ //jquery call String cdid=(String) request.getParameter("cdid"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select instrumentid from mstinstrument where codeid='" + cdid + "' and rec_Status='A' and statusid='U' and Agentid='METLAB'"); if (!rs.wasNull()){ //List data=new ArrayList(); String v="<select id=cboinstr>"; while (rs.next()) { // data.add(rs.getString("vend_code")); v += "<option>" + rs.getString("instrumentid").toString() + "</option>"; } v+="</select>"; response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.print(v); } else{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.print("no data found"); } where i am missing???

    Read the article

  • Getting rejected value null spring validation

    - by Shabarinath
    Hi in my project when I am trying to validate my form its not showing any error messages even if validation fails (Event Form is not submitted and enters into validation fail block) Here is my code /****************** Post Method *************/ @RequestMapping(value="/property", method = RequestMethod.POST) public String saveOrUpdateProperty(@ModelAttribute("property") Property property, BindingResult result, Model model, HttpServletRequest request) throws Exception { try { if(validateFormData(property, result)) { model.addAttribute("property", new Property()); return "property/postProperty"; } } /********* Validate Block *************/ private boolean validateFormData(Property property, BindingResult result) throws DaoException { if (property.getPropertyType() == null || property.getPropertyType().equals("")) { result.rejectValue("propertyType", "Cannot Be Empty !", "Cannot Be Empty !"); } if (property.getTitle() == null || property.getTitle().equals("")) { result.rejectValue("title", "Cannot Be Empty !", "Cannot Be Empty !"); } return (result.hasFieldErrors() || result.hasErrors()); } But when i debug i can see below one org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'property' on field 'title': rejected value [null]; codes [Cannot Be Empty !.property.title,Cannot Be Empty !.title,Cannot Be Empty !.java.lang.String,Cannot Be Empty !]; arguments []; default message [Cannot Be Empty !] and this is how i am displaying in jsp file <div class="control-group"> <div class="controls"> <label class="control-label"><span class="required">* </span>Property Type</label> <div class="controls"> <form:input path="title" placeholder="Pin Code" cssClass="form-control border-radius-4 textField"/> <form:errors path="title" style="color:red;"/> </div> </div> </div> Event though when i see the below one when i debug (1 Error its correct) org.springframework.validation.BeanPropertyBindingResult: 1 errors Why it is not displayed in jsp can any one hep me?

    Read the article

  • Can't access a property with <html:checkbox property="..."> when iterating a list

    - by Bernhard V
    Hi. In my Struts form I've got a list. In a JSP I iterate over it like this: <c:forEach items="${MyForm.auspraegungen}" var="auspraegung"> <tr> <td>${auspraegung.name}</td> <td>${auspraegung.forced}</td> <td>${auspraegung.cbx_uebernehmen}</td> <html:checkbox property="auspraegung.cbx_uebernehmen" /> </tr> </c:forEach> Now the <html:checkbox isn't working. I'm always getting the following error: Caused by: javax.servlet.jsp.JspException: No getter method for property auspraegung.cbx_uebernehmen of bean org.apache.struts.taglib.html.BEAN But actually there is a getter for this property in my form class. It's written like this: public Boolean getCbx_uebernehmen() { return cbx_uebernehmen; } When I remove the checkbox it's also possible to display the property as in the <td>-tag above so I don't know where the problem is. Maybe I'm accessing it in the wrong way?

    Read the article

  • This page calls for XML namespace declared with prefix br but no taglibrary exists

    - by Christopher W. Allen-Poole
    I just finished the Netbeans introduction to Hibernate tutorial ( http://netbeans.org/kb/docs/web/hibernate-webapp.html#01 ) and I am getting the following error: "This page calls for XML namespace declared with prefix br but no taglibrary exists" Now, I have seen a similar question somewhere else: http://forums.sun.com/thread.jspa?threadID=5430327 but the answer is not listed there. Or, if it is, then I am clearly missing it -- line one of my index.xhtml file reads "http://www.w3.org/1999/xhtml". It also does not explain why, when I reload localhost:8080, the message disappears. Here is my index.xhtml file: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"> <ui:composition template="./template.xhtml"> <ui:define name="body"> <h:form> <h:commandLink action="#{filmController.previous}" value="Previous #{filmController.pageSize}" rendered="#{filmController.hasPreviousPage}"/> <h:commandLink action="#{filmController.next}" value="Next #{filmController.pageSize}" rendered="#{filmController.hasNextPage}"/> <h:dataTable value="#{filmController.filmTitles}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px"> <h:column> <f:facet name="header"> <h:outputText value="Title"/> </f:facet> <h:outputText value="#{item.title}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Description"/> </f:facet> <h:outputText value="#{item.description}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value=" "/> </f:facet> <h:commandLink action="#{filmController.prepareView}" value="View"/> </h:column> </h:dataTable> <br/> </h:form> </ui:define> </ui:composition> </html>

    Read the article

  • RichFaces rich:insert takes a long time to output large files

    - by Mark Lewis
    Hello I'm using a RichFaces <rich:insert like this: <rich:panel header="my head"> <a4j:outputPanel ajaxRendered="true"> <rich:insert src="#{MyBacking.myPath}" highlight="groovy" /> </a4j:outputPanel> </rich:panel> If I have a 60k file to output, it takes 23 seconds. I've got a requirement to output the contents of some larger files than that and obviously the larger the file, the larger the wait for content. The recommendation in the answer to another related question is to introduce paging. I will, but the question is, why does it take so long to output 60k of text using JSF/RichFaces? That is, reading off a local disk with Windows XP SP2 PC - I can see from the log the data has already been written to disk from the network. Other scripting languages appear to be faster than this - is it something to do with the JSF lifecycle having to handle the text maybe? Thanks

    Read the article

  • Desktop.getDesktop().browse(uri); will open web page on server or client side?

    - by Milan
    Hello everybody, I have a JSF application and when user click on button I want to open a web page. Desktop.getDesktop().browse(uri); probably opens a web page on server side, how to do it on client side? when i try Desktop.getDesktop().browse(uri); it works, but maybe its because I open the JSF application on localhost so I dont know if the opened uri is on server side or client side. In the specification for getDesktop() its written: getDesktop() Returns the Desktop instance of the current browser context. Thanks!

    Read the article

  • CDI SessionScoped Bean instance remains unchanged when login with different user

    - by Jason Yang
    I've been looking for the workaround of this problem for rather plenty of time and no result, so I ask question here. Simply speaking, I'm using a CDI SessionScoped Bean User in my project to manage user information and display them on jsf pages. Also container-managed j_security_check is used to resolve authentication issue. Everything is fine if first logout with session.invalidate() and then login in the same browser tab with a different user. But when I tried to directly login (through login.jsf) with a new user without logout beforehand, I found the user information remaining unchanged. I debugged and found the User bean, as well as the HttpSession instance, always remaining the same if login with different users in the same browser, as long as session.invalidate() not invoked. But oddly, the session id did modified, and I've both checked in Java code and Firebug. org.apache.catalina.session.StandardSessionFacade@5d7b4092 StandardSession[c69a71d19f369d08b5dddbea2ef0] attrName = org.jboss.weld.context.conversation.ConversationIdGenerator : attrValue=org.jboss.weld.context.conversation.ConversationIdGenerator@583c9dd8 attrName = org.jboss.weld.context.ConversationContext.conversations : attrValue = {} attrName = org.jboss.weld.context.http.HttpSessionContext#org.jboss.weld.bean-Discipline-ManagedBean-class com.netease.qa.discipline.profile.User : attrValue = Bean: Managed Bean [class com.netease.qa.discipline.profile.User] with qualifiers [@Any @Default @Named]; Instance: com.netease.qa.discipline.profile.User@c497c7c; CreationalContext: org.jboss.weld.context.CreationalContextImpl@739efd29 attrName = javax.faces.request.charset : attrValue = UTF-8 org.apache.catalina.session.StandardSessionFacade@5d7b4092 StandardSession[c6ab4b0c51ee0a649ef696faef75] attrName = org.jboss.weld.context.conversation.ConversationIdGenerator : attrValue = org.jboss.weld.context.conversation.ConversationIdGenerator@583c9dd8 attrName = com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap : attrValue = {-4968076393130137442={-7694826198761889564=[Ljava.lang.Object;@43ff5d6c}} attrName = org.jboss.weld.context.ConversationContext.conversations : attrValue = {} attrName = org.jboss.weld.context.http.HttpSessionContext#org.jboss.weld.bean-Discipline-ManagedBean-class com.netease.qa.discipline.profile.User : attrValue = Bean: Managed Bean [class com.netease.qa.discipline.profile.User] with qualifiers [@Any @Default @Named]; Instance: com.netease.qa.discipline.profile.User@c497c7c; CreationalContext: org.jboss.weld.context.CreationalContextImpl@739efd29 attrName = javax.faces.request.charset : attrValue = UTF-8 Above block contains two successive logins and their Session info. We can see that the instance(1st row) the same while session id(2nd row) different. Seems that session object is reused to contain different session id and CDI framework manages session bean life cycle in accordance with the session object only(?). I'm wondering whether there could be only one server-side session object within the same browser unless invalidated? Since I'm adopting j_security_check I fancy intercepting it and invalidating old session is not so easy. So is it possible to accomplish the goal without altering the CDI+JSF+j_security_check design that one can relogin with different account in the same or different tab within the same browser? Really look forward for your response. More info: Glassfish v3.1 is my appserver.

    Read the article

  • Why facelets ignore href-attribute of a link when I use <a href="url" jsfc="h:outputLink"> ?

    - by Roman
    I have next facelet composition: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <body> <ui:composition> <ul id="navigation"> <li> <a href="http://google.com" id="google1" jsfc="h:outputLink">google.com</a> </li> <li> <h:outputLink id="google2" value="http://google.com"> <h:outputText id="outputtext" value="google.com"/> </h:outputLink> </li> </ul> </ui:composition> </body> </html> There must be a mistake because what I expected to see is almost the same final html-markup. But actually here is what facelets generated: <ul id="navigation"> <li><a id="google1" name="google1" href="">google.com</a></li> <li><a id="google2" name="google2" href="http://google.com"><span id="outputtext">google.com</span></a> </li> </ul> Why it ignored href attribute of the first link? What is the correct way to do what I'm trying to do? One more additional question: if I'm using jsfc everywhere I can then what should I do with components from f: namespace? Where should be <f:view> placed? Maybe in the template.xhtml? Or I should simply ignore it?

    Read the article

  • Java Framework Choice Question.

    - by Sarang
    We do have many frameworks available in Java. Struts, Swing, JSF 2.0, Spring etc are used as per their priority. Actually, I don't know how many they are as well! But, as I am fresher to Java, even learning after their architecture, I cannot decide which framework can be used with what type of Projects ! Also, I am confused with mixed use of framework like Spring + JSF. What is the benefit to it ? Another thing making me confusing is about the UI components available in market. Like, we do have Primefaces, Ice-faces, MyFaces, Rich-faces. They may or may not have been supporting AJAX in-built. They may contains some bugs as well. What is best choice for Framework + UI component that can directly provide a best feet solution for any project ?

    Read the article

  • Is it possible to use flashvars with JBoss?

    - by Aikanaro
    Hi, I'm part of a team developing a product using JSF 2.0 and I was asked to investigate the possibility of including FusionCharts free in the app. I have tried different ways of inserting a simple chart in a JSF page but with no luck. On of the methods involves using the elements OBJECT and EMBED but hhen I try to use them I get a "null source" error from JBoss. From what I could find online (through Google), I am under the impression that 'flashvars' isn't quite compatible with JBoss. Is anyone here able to confirm this? If this is the case, what workaround would you suggest me? Other ways I also found online didn't show the chart not even an error message. Thanks in advance.

    Read the article

  • Which faces technology for use with GlassFish 2.1 and NetBeans 6.7?

    - by SteJav
    I'm running GlassFish 2.1 and using NetBeans 6.7. I'd like to create a web interface to my data using JSF 1.2. Trouble is, I'm not sure which 'faces' technology to learn (that includes some good documentation). JBoss/RichFaces seem pretty good on documentation, but I'm using GlassFish. Any thoughts? The choices appear overwhelming: Tomahawk Tobago Trinidad ICEfaces RCFaces Netadvantage WebGalileoFaces QuipuKit BluePrints Woodstock JBoss RichFaces Ajax4jsf ILOG Oracle ADF G4JSF Simplica Backbase jenia4faces VisualWebPack DynaFaces IBM Impl Dinamica Mojarra PrimeFaces jQuery OpenFaces ZK ExtJS Anybody had any experience with any of the above and found the documentation to be clear to a beginner? Being a JSF/Web beginner, I tried some ICEFaces, Mojarra tutorials and had a go at getting RichFaces working with NBeans and GlassFish, but no luck. Lots of XML complaints. I'm clearly missing some huge chunks of configuration, but I can't find any documentation to help me. Any suggestions would be much appreciated :-)

    Read the article

  • How to dynamically change the content of a facet in a custom component?

    - by romaintaz
    Hello, Let's consider that I want to extend an existing JSF component, such as the <rich:datatable/>. My main requirement is to dynamically modify the content of a <f:facet>, to change its content. What is the best way to achieve that? Or where is the best place in the code to achieve that? In my faces-config.xml, I have the following declaration: <faces-config> ... <component> <component-type>my.component.dataTable</component-type> <component-class>my.project.component.table.MyHtmlDataTable</component-class> </component> ... <render-kit> <render-kit-id>HTML_BASIC</render-kit-id> <renderer> <component-family>org.richfaces.DataTable</component-family> <renderer-type>my.renderkit.dataTable</renderer-type> <renderer-class>my.project.component.table.MyDataTableRenderer</renderer-class> </renderer> ... Also, my my-project.taglib.xml file (as I use Facelets) looks like: <facelet-taglib> <namespace>http://my.project/jsf</namespace> <tag> <tag-name>dataTable</tag-name> <component> <component-type>my.component.dataTable</component-type> <renderer-type>my.renderkit.dataTable</renderer-type> </component> </tag> So as you can see, I have two classes in my project for my custom datatable: MyHtmlDataTable and MyDataTableRenderer. One of my idea is to modify the content of the <f:facet> directly in the doEncodeBegin() method of my renderer. This is working (in fact almost working), but I don't really think that's the better place to achieve my modification. What do you think? Technical information: JSF 1.2, Facelets, Richfaces 3.3.2, Java 1.6

    Read the article

  • j2me or android file upload to jsp

    - by user313613
    hi i new to mobile development i like to upload the file from blackberry and android how to develop the mobile side to this jsp page. please do reply me thanks here i mention the jsp file from roseindia.net. <%@ page import="java.io.*" % <% //to get the content type information from JSP Request Header String contentType = request.getContentType(); //here we are checking the content type is not equal to Null and as well as the passed data from mulitpart/form-data is greater than or equal to 0 if ((contentType != null) && (contentType.indexOf("multipart/form-data") = 0)) { DataInputStream in = new DataInputStream(request. getInputStream()); //we are taking the length of Content type data int formDataLength = request.getContentLength(); byte dataBytes[] = new byte[formDataLength]; int byteRead = 0; int totalBytesRead = 0; //this loop converting the uploaded file into byte code while (totalBytesRead < formDataLength) { byteRead = in.read(dataBytes, totalBytesRead, formDataLength); totalBytesRead += byteRead; } String file = new String(dataBytes); //for saving the file name String saveFile = file.substring(file.indexOf("filename=\"") + 10); saveFile = saveFile.substring(0, saveFile.indexOf("\n")); saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\"")); int lastIndex = contentType.lastIndexOf("="); String boundary = contentType.substring(lastIndex + 1, contentType.length()); int pos; //extracting the index of file pos = file.indexOf("filename=\""); pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; int boundaryLocation = file.indexOf(boundary, pos) - 4; int startPos = ((file.substring(0, pos)).getBytes()).length; int endPos = ((file.substring(0, boundaryLocation)) .getBytes()).length; // creating a new file with the same name and writing the content in new file FileOutputStream fileOut = new FileOutputStream(saveFile); fileOut.write(dataBytes, startPos, (endPos - startPos)); fileOut.flush(); fileOut.close(); %><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of: <% out.println(saveFile); % <% } %

    Read the article

< Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >