Results 1 to 2 of 2
  1. #1
    Ginkan is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default How to use and print the JAVA code from a JSP

    hi all, im new to JSP, i want to write a JSP that can read the exif infomation from JPEG,
    1)how can i use the $path in <%!
    2)how can i print the data from <%!
    thank U & sorry for my poor english!


    Java Code:
    <%@ page language="java" contentType="text/html; charset=big5" import="java.util.*,*"%>
    <%@ page import="com.drew.metadata.*"%>
    <%@ page import="com.drew.metadata.exif.*"%>
    <%@ page import="com.drew.imaging.jpeg.JpegProcessingException"%>
    Date $date= new Date();
    String $patha=new File(application.getRealPath("/")).getParent();
    String $pathb=new File(request.getRequestURI()).getParent();
    String $path=$patha+$pathb+"\\";
    <!-- client comment, time: <%=$date%> -->
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title>JSP Try - 05_exif</title>
    public static void main(String args[]) throws FileNotFoundException {
    [color=red][b]File f = new File("X:/xxx/xxx.JPG");[/b]
    /*1)Can i change to the following line︰
    [b]File f = new File($path +"xxx.JPG");*/[/b][/color]
    try {
    ExifReader er = new ExifReaderRose;
    Metadata exif = er.extract();
    Iterator itr = exif.getDirectoryIterator();
    while (itr.hasNext()) {
    Directory directory = (Directory);
    /*2)How to print the following lines︰*/
    System.out.println("EXIF版本:" + directory.getString(ExifDirectory.TAG_EXIF_VERSION));
    System.out.println(" 相機品牌:" + directory.getString(ExifDirectory.TAG_MAKE));
    System.out.println(" 像機號碼:" + directory.getString(ExifDirectory.TAG_MODEL));
    System.out.println(" 光圈值:" + directory.getString(ExifDirectory.TAG_FNUMBER));
    System.out.println(" 快門:" + directory.getString(ExifDirectory.TAG_EXPOSURE_TIME));
    System.out.println(" 感光度:" + directory.getString(ExifDirectory.TAG_ISO_EQUIVALENT));
    System.out.println(" 軟件:" + directory.getString(ExifDirectory.TAG_SOFTWARE));
    System.out.println(" 原始拍攝時間:" + directory.getString(ExifDirectory.TAG_DATETIME_ORIGINAL));
    System.out.println(" 數字化時間:" + directory.getString(ExifDirectory.TAG_DATETIME_DIGITIZED));
    System.out.println(" 方向:" + directory.getString(ExifDirectory.TAG_ORIENTATION));
    System.out.println(" 圖片寬度:" + directory.getString(ExifDirectory.TAG_EXIF_IMAGE_WIDTH));
    System.out.println(" 圖片高度:" + directory.getString(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT));
    System.out.println(" 水平分辨率:" + directory.getString(ExifDirectory.TAG_X_RESOLUTION));
    System.out.println(" 垂直分辨率:" + directory.getString(ExifDirectory.TAG_Y_RESOLUTION));
    System.out.println(" 垂直分辨率:" + directory.getString(ExifDirectory.TAG_EXPOSURE_BIAS));
    } catch (JpegProcessingException e) {
    System.err.println("This is not a JPEG - 這不是JPEG檔");

  2. #2
    FON is offline Senior Member
    Join Date
    Dec 2009
    Belgrade, Serbia
    Rep Power


    Do you know what are JSP Implicit Objects?

    Try this scriptlet in your JSP:

    Java Code:
    out.print("Hello World");
    "Out: denotes the Output stream in the context of page. The class or the interface name of the Out object is jsp.JspWriter. The Out object is written: Javax.servlet.jsp.JspWriter"

    They end up visible in the browser requesting the JSP page, not in
    java console as System.out.println(...)

    Writing code in scriptlets is bad habit. Use tags instead.

Similar Threads

  1. Replies: 6
    Last Post: 11-12-2009, 11:50 AM
  2. Replies: 5
    Last Post: 05-25-2009, 09:03 PM
  3. Java code to connect printer to print content
    By wendyz in forum Advanced Java
    Replies: 3
    Last Post: 04-30-2009, 06:51 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. Replies: 11
    Last Post: 04-16-2008, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts