Username.jsp
Code:
HTML>
<BODY>
<FORM METHOD=POST ACTION="Username.jsp">
<INPUT TYPE=TEXT NAME=user SIZE=20>
<P><INPUT TYPE=SUBMIT></P>
<jsp:useBean id="userLog" class="com.UserLog" scope="request"/>
<%
String name = request.getParameter("user");
if(name != null && name.length() > 0) {
userLog.addUser(name);
}
%>
</FORM>
</BODY>
</HTML>
com.UserLog.java
Code:
package com;
public class UserLog {
public UserLog() {}
public void addUser(String username) {
System.out.println(username);
//add the logic to append the username
}
}
Build a war file which should have
UserLog.class --> WEB-INF\classes\com folder
Usename.jsp --> (doc-root)
The additional files may be required depending on what server you are deploying to
<app-server>.xml --> WEB-INF
For example I used JBOSS server to test and had to have
jboss-web.xml --> WEB-INF folder
Code:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web
<context-root>test</context-root>
</jboss-web>
to test: typed the url http://localhost:8080/test/Username.jsp
Hope it helps.
Bookmarks