'작업노트'에 해당되는 글 100건

  1. 2007.09.04 Struts 파일 업로드 유틸 사용시 한글 파일명 깨짐 문제
  2. 2007.08.29 innerHTML을 사용할 시에
  3. 2007.07.17 서블릿을 이용할때 iframe resize가 안되는 경우.. 1
  4. 2007.07.05 404 - Servlet action is not available
  5. 2007.07.02 LinuxFedoraCore6 + Apache2.2 + Tomcat5.5.23 + JDK1.6.0_01
  6. 2007.06.30 How to Install Java in Fedora Core 6 - Java Runtime Environment
  7. 2007.06.27 error while loading shared libraries
  8. 2007.06.01 javax.servlet.ServletException: You have an error in your SQL syntax;
  9. 2007.05.31 HTML 객체 계층도
  10. 2007.05.29 Vector or ArrayList -- which is better?

Struts 파일 업로드 유틸 사용시 한글 파일명 깨짐 문제

|

스트럿츠에서 자공하는 파일업로드 유틸을 사용할 경우
데이터 베이스에 한글 파일명은 깨져서 기입되는데,
결국은 방법을 찾아내었다.
다음과 같이 필터를 사용하면 된다.


package study.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodingFilter implements Filter {
   
    private String encoding = null;
    protected FilterConfig filterConfig = null;
   
    public void destroy() {
        this.encoding = null;
        this.filterConfig = null;
    }
   
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
        if(request.getCharacterEncoding() == null) {
            if(encoding != null) {
                request.setCharacterEncoding(encoding);
            }           
        }
       chain.doFilter(request, response);
    }   
   
    public void init(FilterConfig filterConfig) throws ServletException {
         this.filterConfig = filterConfig;
         this.encoding = filterConfig.getInitParameter("encoding");
    }
   
    public FilterConfig getFilterConfig() {
        return filterConfig;
    }
   
    public void setFilterConfig(FilterConfig cfg) {
        filterConfig = cfg;
    }  
}


위와같이 클래스를 생성하고
web.xml에서 필터를 등록한다.


    <web-app>


        <filter>
            <filter-name>Encoding Filter</filter-name>           
            <filter-class>study.filter.EncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>EUC-KR</param-value>           
            </init-param>
        </filter>

        <filter-mapping>
            <filter-name>Encoding Filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>


    </web-app>

And

innerHTML을 사용할 시에

|

타겟으로 사용되는 <div>태그에 제대로 내용이 나타나지 않았는데,

<tr><td>로 묶어주니 제대로 표현이 되었다.

<tr><td>
      <div id="photos"> </div>
  </td></tr>

이런식으로.

And

서블릿을 이용할때 iframe resize가 안되는 경우..

|
외부에서 서블릿.do?action=액션명 이런식으로 접근할 필요가 생겼다. 그런데..

인터넷에 돌고 있는 아이프레임의 리사이즈 함수들은
서블릿을 통해 부모페이지가 로드될경우 리사이즈 되지가 않는다.
(왜그런지는 모르겠으나.. 크기를 제대로 잡지 못한다.)


<script>
    var ifrContentsTimer;
    function resizeRetry() { //로딩 완료후 다시한번 리사이즈
    if(document.body.readyState == "complete") {
    clearInterval(ifrContentsTimer);
    } else {
    resizeFrame();
    }
    }
   
    function resizeFrame(){ //로딩 즉시 리사이즈
    self.resizeTo(document.body.scrollWidth + (document.body.offsetWidth-document.body.clientWidth), parseInt(document.body.scrollHeight)+10);
    }
</script>


<body onload="resizeFrame();ifrContentsTimer = setInterval('resizeRetry()', 100);">


아이프레임에 들어갈 문서(자식 페이지)에 위 내용을 추가/수정한다.
아마도 서블릿 매핑하는 과정이 오래걸려서?? 로딩이 완료되지 않은 상태로
리사이즈 되는 모냥이다.

'작업노트 > HTML & Script' 카테고리의 다른 글

아이프레임 리사이즈 문제 해법  (0) 2008.01.05
name과 id의 차이  (0) 2007.09.15
GET방식으로 한글 보내는 방법  (0) 2007.09.04
innerHTML을 사용할 시에  (0) 2007.08.29
HTML 객체 계층도  (0) 2007.05.31
And

404 - Servlet action is not available

|

여러가지 경우에 이 메세지가 뜰 수 있으나

이번 경우는

dbcp파일을 tomcat/common/lib 폴더에 두지 않아 생긴 문제

struts-config.xml 파일에서 data-source설정 부분에서

org.apache.commons.dbcp.BasicDataSource 를 찾지 못한것이다.

사소한거라 잊기 쉬우니 항상 기억하자.

And

LinuxFedoraCore6 + Apache2.2 + Tomcat5.5.23 + JDK1.6.0_01

|

LinuxFedoraCore6 + Apache2.2 + Tomcat5.5.23 + JDK1.6.0_01

1.리눅스 설치
공짜인 fedora core6란 놈으로 설치결정.
무조건 yes yes로 설치 종료-_-


2.아파치 설치
http://httpd.apache.org/download.cgi 이곳에서
httpd-2.2.4.tar.gz 라는 녀석을 다운받는다.

/usr/local/ 로 파일을 옮기고 압축을 푼다.
shell> tar zxvf httpd-2.2.4.tar.gz

압축을 푼 디렉토리로 이동
shell> cd httpd-2.2.4

설치를 한다.(과정에 대한 자세한 사항은 모르겠음ㅠ)
shell> ./configure --prefix=/usr/local/apache2 \(아파치가 설치될 디렉토리)
> --enable-rule=SHARED_CORE \(톰캣연동시 필요하다고..)
> --enable-modules=so \(역시 톰캣연동에 필요.)
> --enable-so (php연동시 필요하다고 한다.)
(사실 나는 첫째 줄 옵션만 적용..;;)

shell> make
shell> make install
설치 완료

shell> service httpd start 또는
shell> /usr/local/apache2/bin/apachectl start
로 아파치를 구동한다..
위, 아래 방법의 차이는 나도 모르겠다.
어떻게 service명령어로 실행이 가능한지도.. 아.. 공부해야하나 리눅스..ㅠ
가시적인 차이라면 service로 구동시키면 OK 라는 메세지를 날려주시는데
apachectl은 아무런 반응도 안보이신다. 리눅스께서..


3. JDK설치
http://java.sun.com/javase/downloads/index.jsp
이곳에서 jdk를 다운받는다.(jdk-6u1-linux-i586.rpm.bin)
페도라5에서 jdk를 rpm으로 깔게되면 경로상의 문제가 많이 발생한다는 글을
돌아다니다 본적이 있는데.. 페도라6에서는... 문제 없는듯하다.

다음,
/usr/local/ 디렉토리에 위치시킨후 실행이 가능하도록 권한을 변경한다.
shell> chmod 755 jdk-6u1-linux-i586.rpm.bin

그다음은 설치~
shell> jdk-6u1-linux-i586.rpm.bin
(중간에 y눌러서 라이센스에 동의해준다.)

그다음 파이어 폭스의 플러그인에서 사용하는 java의 링크를 변경한다
shell> ln -s /usr/java/jdk1.6.0_01/jre/plugin/i386/ns7/libjavaplugin_oji.so \
> /usr/lib/mozilla/plugins/libjavaplugin_oji.so

다음은 패스 설정
shell> vi /etc/profile 
내용중에 적당한 위치에 다음 구문을 추가

export JAVA_HOME=/usr/java/jdk1.6.0_01
export JRE_HOME=/usr/java/jdk1.6.0_01/jre

다음은 버전확인
shell> java -version

java version "1.6.0_01" 처럼 나오면 완료.
하지만 1.4.2버전으로 나왔는데 그이유는
alternatives에서 java가 manual mode로
1.4.2버전 디렉토리를 링크로 삼고있어서 그렇다고 한다.
(fedora에 포함된 기본 자바 버전)
이럴땐 다음과 같이 해준다.

shell> alternatives --auto java

or

shell> alternatives --confige java 입력후
출력되는 경로중에 알맞은 것을 선택!


4. 톰캣 설치
http://tomcat.apache.org/download-55.cgi 이곳에서
5.5.23버전을 받는다. (core라고 되있는녀석)

apache-tomcat-5.5.23.tar.gz라는 녀석을
역시 /usr/local/로 이동시킨후

푼다.
shell> tar zxvf apache-tomcat-5.5.23.tar.gz

디렉토리 이름이 너무 길어서 맘에 안든다.
심볼릭 링크를 한다.
shell> ln -s apache-tomcat-5.5.23 tomcat

그다음은..
usr/local/tomcat/conf/context.xml을 텍스트 편집기로 열어서 다음과 같이 수정.

  <Context reloadable="true">

usr/local/tomcat/conf/server.xml를 텍스트편집기로 열고,

  <Host name="localhost"... 처럼 시작되는 곳 밑에 아래내용을 추가한다.

     <Context path="" docBase="" debug="0" allowLinking="true"/>
     <Listener className="org.apache.catalina.startup.UserConfig" directoryName="public_html" userClass="org.apache.catalina.startup.PasswdUserDatabase"/>

usr/local/tomcat/conf/web.xml 을 열고

다음과 같은 부분을 찾아 주석을 해제한다.
<servlet>
  <servlet-name>invoker</servlet-name>
   <servlet-class>org.apache.catalina.servlets.InvokerServlet</servlet-class>
   <init-param>
     <param-name>debug</param-name>
     <param-value>0</param-value>
   </init-param>

   <load-on-startup>2</load-on-startup>
</servlet>


이부분도 주석해제
<servlet-mapping>
  <servlet-name>invoker</servlet-name>
  <url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

(이 부분은 확실히.. 아무생각없이 따라했다..)
 
5. 커넥터 설치
이거 아직도 잘 모르겠다..

'작업노트 > LINUX' 카테고리의 다른 글

cronExpress  (0) 2009.01.09
아파치 1.3 + 톰캣 5.0 연동  (0) 2008.12.15
How to Install Java in Fedora Core 6 - Java Runtime Environment  (0) 2007.06.30
And

How to Install Java in Fedora Core 6 - Java Runtime Environment

|
(출처 : http://news.softpedia.com/news/How-to-Install-Java-in-Fedora-Core-6-39724.shtml)

By default, Fedora Core 6 systems come with an old Java software installed, so you need to install a newer version of Java Runtime Environment to enjoy all the Java applications out there. In this quick guide, I will teach you how to update/install your Java Environment.

Let's begin by downloading the latest version of JRE (Java Runtime Environment) from here. Just click on the Download link where it says Java Runtime Environment (JRE) 5.0 Update, then you’ll need to accept the license and download the Linux self-extracting file.

WARNING: Please remember to always replace the xx from the jre-1_5_0_xx-linux-i586.bin file with the latest version. At the moment of this guide’s writing, the latest version was 09, so the file should look like this: jre-1_5_0_09-linux-i586.bin

After you have finished downloading the file, you need to move it into the /opt folder. Open a console and type:

mv jre-1_5_0_xx-linux-i586.bin /opt

Now, you will need to make this file executable so you can extract it. Follow the commands below:

cd /opt - so you can go into the /opt directory
chmod +x jre-1_5_0_xx-linux-i586.bin

And now, let's run the executable file with the following command:

./jre-1_5_0_xx-linux-i586.bin

You'll be prompted with the License Agreement, hit space until you are asked if you agree or not. Type Yes and the extraction process will begin. After the extraction process is finished, just remove the binary file with the following command:

rm -rf jre-1_5_0_xx-linux-i586.bin

Now, let's put the Java plugin into your browser's plugin folder. Konqueror, Firefox and Mozilla browsers will all look into the same folder, for plugins. So type the following command:

ln -s /opt/jre1.5.0_xx/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin_oji.so

Well, now you need to make the Java executable available for the whole system, so you can run all the Java applications you encounter. Create the following file with your preferred text editor:

kwrite /etc/profile.d/java.sh

Now paste the following options into the file, remember to enter a carriage return after these lines, then save it. Remember to replace the xx with the latest version you have downloaded:

export J2RE_HOME=/opt/jre1.5.0_xx
export PATH=$J2RE_HOME/bin:$PATH


Now, type the following command to make that file available:

source /etc/profile.d/java.sh

Then type this command to see if the path is correct:

which java

You will see something like this: /opt/jre1.5.0_09/bin/java

Then type these commands:

/usr/sbin/alternatives --install /usr/bin/java java /opt/jre1.5.0_xx/bin/java 2
/usr/sbin/alternatives --config java

After you have entered the last command, you'll be asked to choose which Java software you want for your system. Just press 2 key and hit enter.

And finally, just type this command to see if everything looks good and your system has a new Java Environment:

/usr/sbin/alternatives --display java

And you can also type this command to see the version of your Java Runtime Environment:

java -version

Mine looks like this:

java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode, sharing)


You should now be able to run most of the Java applications out there, with the commands like:

java -jar application.jar

or

javaws application.jnlp

Enjoy!

'작업노트 > LINUX' 카테고리의 다른 글

cronExpress  (0) 2009.01.09
아파치 1.3 + 톰캣 5.0 연동  (0) 2008.12.15
LinuxFedoraCore6 + Apache2.2 + Tomcat5.5.23 + JDK1.6.0_01  (0) 2007.07.02
And

error while loading shared libraries

|
error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory

해결책은...
root>#yum install libstdc++.so.5

출처 : Tong - ssabro님의 UNIX/Linux통

And

javax.servlet.ServletException: You have an error in your SQL syntax;

|

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=5' at line 1
	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=5' at line 1
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
	com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
	com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
	com.mysql.jdbc.Connection.execSQL(Connection.java:3243)
	com.mysql.jdbc.Connection.execSQL(Connection.java:3172)
	com.mysql.jdbc.Statement.executeQuery(Statement.java:1197)
	org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
	myclasses.BbsDAO.getArticle(BbsDAO.java:84)
	myclasses.BbsDAO.getArticle(BbsDAO.java:71)
	myclasses.BbsAction.execute(BbsAction.java:49)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.


mysql DB에서 rcount는 int(6)으로 되어있다.
그런데 DAO class 예제상의 코드에서는

long rcount = rs.getLong("rcount");
rs.updateLong("rcount", rcount+1);

이처럼 long형으로 처리하고 있다.
그래서 long->int로 바꾸었더니 자알~ 된다!

역시 책에 있는 예제라고 100% 믿을건 못되는 듯 하다.

And

HTML 객체 계층도

|
사용자 삽입 이미지


And

Vector or ArrayList -- which is better?

|

By Tony Sintes, JavaWorld.com, 06/22/01

(http://www.javaworld.com/javaworld/javaqa/2001-06/03-qa-0622-vector.html)




Answer:

Sometimes Vector is better; sometimes ArrayList is better; sometimes you don't want to use either. I hope you weren't looking for an easy answer because the answer depends upon what you are doing. There are four factors to consider:

  • API
  • Synchronization
  • Data growth
  • Usage patterns



 

Let's explore each in turn.

API

In The Java Programming Language (Addison-Wesley, June 2000) Ken Arnold, James Gosling, and David Holmes describe the Vector as an analog to the ArrayList. So, from an API perspective, the two classes are very similar. However, there are still some major differences between the two classes.

Synchronization

Vectors are synchronized. Any method that touches the Vector's contents is thread safe. ArrayList, on the other hand, is unsynchronized, making them, therefore, not thread safe. With that difference in mind, using synchronization will incur a performance hit. So if you don't need a thread-safe collection, use the ArrayList. Why pay the price of synchronization unnecessarily?

Data growth

Internally, both the ArrayList and Vector hold onto their contents using an Array. You need to keep this fact in mind while using either in your programs. When you insert an element into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent. Depending on how you use these classes, you could end up taking a large performance hit while adding new elements. It's always best to set the object's initial capacity to the largest capacity that your program will need. By carefully setting the capacity, you can avoid paying the penalty needed to resize the internal array later. If you don't know how much data you'll have, but you do know the rate at which it grows, Vector does possess a slight advantage since you can set the increment value.

Usage patterns

Both the ArrayList and Vector are good for retrieving elements from a specific position in the container or for adding and removing elements from the end of the container. All of these operations can be performed in constant time -- O(1). However, adding and removing elements from any other position proves more expensive -- linear to be exact: O(n-i), where n is the number of elements and i is the index of the element added or removed. These operations are more expensive because you have to shift all elements at index i and higher over by one element. So what does this all mean?

It means that if you want to index elements or add and remove elements at the end of the array, use either a Vector or an ArrayList. If you want to do anything else to the contents, go find yourself another container class. For example, the LinkedList can add or remove an element at any position in constant time -- O(1). However, indexing an element is a bit slower -- O(i) where i is the index of the element. Traversing an ArrayList is also easier since you can simply use an index instead of having to create an iterator. The LinkedList also creates an internal object for each element inserted. So you have to be aware of the extra garbage being created.

Finally, in "PRAXIS 41" from Practical Java (Addison-Wesley, Feb. 2000) Peter Haggar suggests that you use a plain old array in place of either Vector or ArrayList -- especially for performance-critical code. By using an array you can avoid synchronization, extra method calls, and suboptimal resizing. You just pay the cost of extra development time.

------------------------------------------------------------------------------------

아무래도 가장중요한건


스레드 안전 여부.

'작업노트 > JAVA' 카테고리의 다른 글

CSV파일  (0) 2009.03.02
자바 5 에서의 반복자와 컬렉션(for/in 반복문)  (0) 2008.02.28
Java API Map  (0) 2008.01.05
JVM 메모리구조와 스택 - 참조 ^^  (0) 2007.11.19
자바에서 swap 구현하기  (0) 2007.11.19
And
prev | 1 | ··· | 6 | 7 | 8 | 9 | 10 | next