开发者

Allowing the user to upload a file

开发者 https://www.devze.com 2023-03-25 08:06 出处:网络
I\'m working on a university assignment where we\'re building a website that allows students to see available courses, enlist in them, show them their timetable, etc. When the user sees his timetable,

I'm working on a university assignment where we're building a website that allows students to see available courses, enlist in them, show them their timetable, etc. When the user sees his timetable, it is produced in XML and we're using XSLT to view it (as in a previous question I asked). There are currently two different XSLT files and the user can choose (via a dropdown menu) which "theme" he wants to use.

We were asked to allow the user to upload his own .xsl file and have it added to the list of themes (available to anyone). To accommodate this demand, I created a new XML file, called timetable_themes.xml which looks something like this:

<?xml version="1.0" encoding="UTF-8"?>开发者_Python百科;
<!DOCTYPE TimetableThemes SYSTEM "timetable_themes.dtd" >
<TimetableThemes>
  <Theme>
    <Name>Classic</Name>
    <FileName>classic.xsl</FileName>
  </Theme>
  <Theme>
    <Name>Bullets</Name>
    <FileName>bullets.xsl</FileName>
  </Theme>
</TimetableThemes>

This file lists the different themes available and their file names. This XML file, and the XSL files reside at WebContent/timetable. The two themes currently available were designed by us, but we need to allow the user to upload his.

My question is - how do I allow a user to upload files, how do I choose where to save them in the server? and thirdly - is my XML solution for the theme list a good idea?


Shalom Amir, use this to retrieve a file upload from a form have contructed.


how do I allow a user to upload files

Use <form method="post" enctype="multipart/form-data"><input type="file"> in HTML/JSP side and use Apache Commons FileUpload to parse it, or when you're already using Servlet 3.0 capable container, use HttpServletRequest#getParts(). See also How to upload files to server using JSP/Servlet?


how do I choose where to save them in the server?

At least not in the public webcontent. All new files would get lost whenever you redeploy the webapp or even when you restart the server. Store them in the local disk file system using FileOutputStream, or if that's not an option, in the DB using PreparedStatement#setBinaryStream().


is my XML solution for the theme list a good idea?

This is not a question which can be objectively answered. It really depends on too many factors. Try a discussion forum instead of a Q&A site.

0

精彩评论

暂无评论...
验证码 换一张
取 消